1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-30 05:02:26 -05:00

Merge branch 'master' into pgp_mime_preparations

This commit is contained in:
cketti 2015-03-03 00:33:45 +01:00
commit bf344dee5d
3 changed files with 170 additions and 127 deletions

View File

@ -1,5 +1,6 @@
package com.fsck.k9.activity; package com.fsck.k9.activity;
import android.support.test.runner.AndroidJUnit4; import android.support.test.runner.AndroidJUnit4;
import com.fsck.k9.mail.Flag; import com.fsck.k9.mail.Flag;
@ -8,84 +9,148 @@ import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotNull; import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertNull; import static junit.framework.Assert.assertNull;
import static junit.framework.Assert.assertTrue;
@RunWith(AndroidJUnit4.class) @RunWith(AndroidJUnit4.class)
public class MessageReferenceTest public class MessageReferenceTest {
{
/**
* Typically happens during forwards. (You have a reference, but no flag since we don't currently consider FORWARDED a flag.)
*/
@Test @Test
public void testIdentityStringNoFlag() public void checkIdentityStringFromMessageReferenceWithoutFlag() {
{ MessageReference messageReference = createMessageReference("o hai!", "folder", "10101010");
MessageReference mr = new MessageReference();
mr.accountUuid = "o hai!";
mr.folderName = "folder";
mr.uid = "10101010";
assertEquals("!:byBoYWkh:Zm9sZGVy:MTAxMDEwMTA=", mr.toIdentityString()); assertEquals("!:byBoYWkh:Zm9sZGVy:MTAxMDEwMTA=", messageReference.toIdentityString());
}
/**
* Typically happens during replies.
*/
@Test
public void testIdentityString()
{
MessageReference mr = new MessageReference();
mr.accountUuid = "o hai!";
mr.folderName = "folder";
mr.uid = "10101010";
mr.flag = Flag.ANSWERED;
assertEquals("!:byBoYWkh:Zm9sZGVy:MTAxMDEwMTA=:ANSWERED", mr.toIdentityString());
} }
@Test @Test
public void testParseIdentityStringNoFlag() throws MessagingException public void checkIdentityStringFromMessageReferenceWithFlag() {
{ MessageReference messageReference =
MessageReference mr = new MessageReference("!:byBoYWkh:Zm9sZGVy:MTAxMDEwMTA="); createMessageReferenceWithFlag("o hai!", "folder", "10101010", Flag.ANSWERED);
assertEquals("o hai!", mr.accountUuid);
assertEquals("folder", mr.folderName); assertEquals("!:byBoYWkh:Zm9sZGVy:MTAxMDEwMTA=:ANSWERED", messageReference.toIdentityString());
assertEquals("10101010", mr.uid);
assertNull(mr.flag);
} }
@Test @Test
public void testParseIdentityString() throws MessagingException public void parseIdentityStringWithoutFlag() throws MessagingException {
{ MessageReference messageReference = new MessageReference("!:byBoYWkh:Zm9sZGVy:MTAxMDEwMTA=");
MessageReference mr = new MessageReference("!:byBoYWkh:Zm9sZGVy:MTAxMDEwMTA=:ANSWERED");
assertEquals("o hai!", mr.accountUuid); assertEquals("o hai!", messageReference.accountUuid);
assertEquals("folder", mr.folderName); assertEquals("folder", messageReference.folderName);
assertEquals("10101010", mr.uid); assertEquals("10101010", messageReference.uid);
assertEquals(Flag.ANSWERED, mr.flag); assertNull(messageReference.flag);
} }
@Test @Test
public void testBadVersion() throws MessagingException public void parseIdentityStringWithFlag() throws MessagingException {
{ MessageReference messageReference = new MessageReference("!:byBoYWkh:Zm9sZGVy:MTAxMDEwMTA=:ANSWERED");
MessageReference mr = new MessageReference("@:byBoYWkh:Zm9sZGVy:MTAxMDEwMTA=:ANSWERED");
assertNull(mr.accountUuid); assertEquals("o hai!", messageReference.accountUuid);
assertEquals("folder", messageReference.folderName);
assertEquals("10101010", messageReference.uid);
assertEquals(Flag.ANSWERED, messageReference.flag);
}
@Test
public void parseIdentityStringContainingBadVersionNumber() throws MessagingException {
MessageReference messageReference = new MessageReference("@:byBoYWkh:Zm9sZGVy:MTAxMDEwMTA=:ANSWERED");
assertNull(messageReference.accountUuid);
} }
@Test(expected = MessagingException.class) @Test(expected = MessagingException.class)
public void testNull() throws MessagingException public void parseNullIdentityString() throws MessagingException {
{
new MessageReference(null); new MessageReference(null);
} }
@Test(expected = MessagingException.class) @Test(expected = MessagingException.class)
public void testCorruption() throws MessagingException public void parseIdentityStringWithCorruptFlag() throws MessagingException {
{
MessageReference mr = new MessageReference("!:%^&%^*$&$by&(BYWkh:Zm9%^@sZGVy:MT-35#$AxMDEwMTA=:ANSWERED");
// No idea what this is going to generate, but it should be non-null.
assertNotNull(mr.accountUuid);
assertNotNull(mr.folderName);
assertNotNull(mr.uid);
// Corruption in the Flag should throw MessagingException.
new MessageReference("!:%^&%^*$&$by&(BYWkh:Zm9%^@sZGVy:MT-35#$AxMDEwMTA=:ANSWE!RED"); new MessageReference("!:%^&%^*$&$by&(BYWkh:Zm9%^@sZGVy:MT-35#$AxMDEwMTA=:ANSWE!RED");
} }
@Test
public void equalsWithAnObjectShouldReturnFalse() {
MessageReference messageReference = new MessageReference();
Object object = new Object();
assertFalse(messageReference.equals(object));
}
@SuppressWarnings("ObjectEqualsNull")
@Test
public void equalsWithNullShouldReturnFalse() {
MessageReference messageReference = createMessageReference("account", "folder", "uid");
assertFalse(messageReference.equals(null));
}
@Test
public void equalsWithSameMessageReferenceShouldReturnTrue() {
MessageReference messageReference = createMessageReference("account", "folder", "uid");
assertTrue(messageReference.equals(messageReference));
}
@Test
public void equalsWithMessageReferenceContainingSameDataShouldReturnTrue() {
MessageReference messageReferenceOne = createMessageReference("account", "folder", "uid");
MessageReference messageReferenceTwo = createMessageReference("account", "folder", "uid");
assertEqualsReturnsTrueSymmetrically(messageReferenceOne, messageReferenceTwo);
}
@Test
public void equalsWithMessageReferenceContainingDifferentAccountUuidShouldReturnFalse() {
MessageReference messageReferenceOne = createMessageReference("account", "folder", "uid");
MessageReference messageReferenceTwo = createMessageReference("-------", "folder", "uid");
assertEqualsReturnsFalseSymmetrically(messageReferenceOne, messageReferenceTwo);
}
@Test
public void equalsWithMessageReferenceContainingDifferentFolderNameShouldReturnFalse() {
MessageReference messageReferenceOne = createMessageReference("account", "folder", "uid");
MessageReference messageReferenceTwo = createMessageReference("account", "------", "uid");
assertEqualsReturnsFalseSymmetrically(messageReferenceOne, messageReferenceTwo);
}
@Test
public void equalsWithMessageReferenceContainingDifferentUidShouldReturnFalse() {
MessageReference messageReferenceOne = createMessageReference("account", "folder", "uid");
MessageReference messageReferenceTwo = createMessageReference("account", "folder", "---");
assertEqualsReturnsFalseSymmetrically(messageReferenceOne, messageReferenceTwo);
}
private MessageReference createMessageReference(String accountUuid, String folderName, String uid) {
MessageReference messageReference = new MessageReference();
messageReference.accountUuid = accountUuid;
messageReference.folderName = folderName;
messageReference.uid = uid;
return messageReference;
}
private MessageReference createMessageReferenceWithFlag(String accountUuid, String folderName, String uid,
Flag flag) {
MessageReference messageReference = new MessageReference();
messageReference.accountUuid = accountUuid;
messageReference.folderName = folderName;
messageReference.uid = uid;
messageReference.flag = flag;
return messageReference;
}
private void assertEqualsReturnsTrueSymmetrically(MessageReference referenceOne, MessageReference referenceTwo) {
assertTrue(referenceOne.equals(referenceTwo));
assertTrue(referenceTwo.equals(referenceOne));
}
private void assertEqualsReturnsFalseSymmetrically(MessageReference referenceOne, MessageReference referenceTwo) {
assertFalse(referenceOne.equals(referenceTwo));
assertFalse(referenceTwo.equals(referenceOne));
}
} }

View File

@ -14,6 +14,7 @@ import com.fsck.k9.Preferences;
import com.fsck.k9.R; import com.fsck.k9.R;
import com.fsck.k9.activity.K9Activity; import com.fsck.k9.activity.K9Activity;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException;
/** /**
* Prompts the user to select an account type. The account type, along with the * Prompts the user to select an account type. The account type, along with the
@ -22,11 +23,9 @@ import java.net.URI;
*/ */
public class AccountSetupAccountType extends K9Activity implements OnClickListener { public class AccountSetupAccountType extends K9Activity implements OnClickListener {
private static final String EXTRA_ACCOUNT = "account"; private static final String EXTRA_ACCOUNT = "account";
private static final String EXTRA_MAKE_DEFAULT = "makeDefault"; private static final String EXTRA_MAKE_DEFAULT = "makeDefault";
private Account mAccount; private Account mAccount;
private boolean mMakeDefault; private boolean mMakeDefault;
public static void actionSelectAccountType(Context context, Account account, boolean makeDefault) { public static void actionSelectAccountType(Context context, Account account, boolean makeDefault) {
@ -49,45 +48,20 @@ public class AccountSetupAccountType extends K9Activity implements OnClickListen
mMakeDefault = getIntent().getBooleanExtra(EXTRA_MAKE_DEFAULT, false); mMakeDefault = getIntent().getBooleanExtra(EXTRA_MAKE_DEFAULT, false);
} }
private void onPop() { private void setupStoreAndSmtpTransport(String schemePrefix) throws URISyntaxException {
try { URI storeUriForDecode = new URI(mAccount.getStoreUri());
URI uri = new URI(mAccount.getStoreUri()); URI storeUri = new URI(schemePrefix, storeUriForDecode.getUserInfo(), storeUriForDecode.getHost(),
uri = new URI("pop3+ssl+", uri.getUserInfo(), uri.getHost(), uri.getPort(), null, null, null); storeUriForDecode.getPort(), null, null, null);
mAccount.setStoreUri(uri.toString()); mAccount.setStoreUri(storeUri.toString());
uri = new URI(mAccount.getTransportUri()); URI transportUriForDecode = new URI(mAccount.getTransportUri());
uri = new URI("smtp+tls+", uri.getUserInfo(), uri.getHost(), uri.getPort(), null, null, null); URI transportUri = new URI("smtp+tls+", transportUriForDecode.getUserInfo(), transportUriForDecode.getHost(),
mAccount.setTransportUri(uri.toString()); transportUriForDecode.getPort(), null, null, null);
mAccount.setTransportUri(transportUri.toString());
AccountSetupIncoming.actionIncomingSettings(this, mAccount, mMakeDefault);
finish();
} catch (Exception use) {
failure(use);
} }
} private void setupDav() throws URISyntaxException {
URI uriForDecode = new URI(mAccount.getStoreUri());
private void onImap() {
try {
URI uri = new URI(mAccount.getStoreUri());
uri = new URI("imap+ssl+", uri.getUserInfo(), uri.getHost(), uri.getPort(), null, null, null);
mAccount.setStoreUri(uri.toString());
uri = new URI(mAccount.getTransportUri());
uri = new URI("smtp+tls+", uri.getUserInfo(), uri.getHost(), uri.getPort(), null, null, null);
mAccount.setTransportUri(uri.toString());
AccountSetupIncoming.actionIncomingSettings(this, mAccount, mMakeDefault);
finish();
} catch (Exception use) {
failure(use);
}
}
private void onWebDav() {
try {
URI uri = new URI(mAccount.getStoreUri());
/* /*
* The user info we have been given from * The user info we have been given from
@ -97,35 +71,39 @@ public class AccountSetupAccountType extends K9Activity implements OnClickListen
* URI. Re-encode without it, using just the UserName and Password. * URI. Re-encode without it, using just the UserName and Password.
*/ */
String userPass = ""; String userPass = "";
String[] userInfo = uri.getUserInfo().split(":"); String[] userInfo = uriForDecode.getUserInfo().split(":");
if (userInfo.length > 1) { if (userInfo.length > 1) {
userPass = userInfo[1]; userPass = userInfo[1];
} }
if (userInfo.length > 2) { if (userInfo.length > 2) {
userPass = userPass + ":" + userInfo[2]; userPass = userPass + ":" + userInfo[2];
} }
uri = new URI("webdav+ssl+", userPass, uri.getHost(), uri.getPort(), null, null, null); URI uri = new URI("webdav+ssl+", userPass, uriForDecode.getHost(), uriForDecode.getPort(), null, null, null);
mAccount.setStoreUri(uri.toString()); mAccount.setStoreUri(uri.toString());
AccountSetupIncoming.actionIncomingSettings(this, mAccount, mMakeDefault);
finish();
} catch (Exception use) {
failure(use);
}
} }
public void onClick(View v) { public void onClick(View v) {
try {
switch (v.getId()) { switch (v.getId()) {
case R.id.pop: case R.id.pop: {
onPop(); setupStoreAndSmtpTransport("pop3+ssl+");
break;
case R.id.imap:
onImap();
break;
case R.id.webdav:
onWebDav();
break; break;
} }
case R.id.imap: {
setupStoreAndSmtpTransport("imap+ssl+");
break;
}
case R.id.webdav: {
setupDav();
break;
}
}
} catch (Exception ex) {
failure(ex);
}
AccountSetupIncoming.actionIncomingSettings(this, mAccount, mMakeDefault);
finish();
} }
private void failure(Exception use) { private void failure(Exception use) {

View File

@ -347,7 +347,7 @@ public class AccountSetupBasics extends K9Activity
} }
} }
protected void onNext() { private void onNext() {
if (mClientCertificateCheckBox.isChecked()) { if (mClientCertificateCheckBox.isChecked()) {
// Auto-setup doesn't support client certificates. // Auto-setup doesn't support client certificates.