Search in sources :

Example 6 with Recipient

use of com.fsck.k9.view.RecipientSelectView.Recipient in project k-9 by k9mail.

the class RecipientSelectView method initView.

private void initView(Context context) {
    // TODO: validator?
    alternatesPopup = new ListPopupWindow(context);
    alternatesAdapter = new AlternateRecipientAdapter(context, this);
    alternatesPopup.setAdapter(alternatesAdapter);
    // don't allow duplicates, based on equality of recipient objects, which is e-mail addresses
    allowDuplicates(false);
    // if a token is completed, pick an entry based on best guess.
    // Note that we override performCompletion, so this doesn't actually do anything
    performBestGuess(true);
    adapter = new RecipientAdapter(context);
    setAdapter(adapter);
    setLongClickable(true);
}
Also used : ListPopupWindow(android.widget.ListPopupWindow) AlternateRecipientAdapter(com.fsck.k9.activity.AlternateRecipientAdapter) RecipientAdapter(com.fsck.k9.activity.compose.RecipientAdapter) AlternateRecipientAdapter(com.fsck.k9.activity.AlternateRecipientAdapter)

Example 7 with Recipient

use of com.fsck.k9.view.RecipientSelectView.Recipient in project k-9 by k9mail.

the class RecipientPresenterTest method testInitFromReplyToMessage.

@Test
public void testInitFromReplyToMessage() throws Exception {
    Message message = mock(Message.class);
    when(replyToParser.getRecipientsToReplyTo(message, account)).thenReturn(TO_ADDRESSES);
    recipientPresenter.initFromReplyToMessage(message, false);
    verify(recipientMvpView).addRecipients(eq(RecipientType.TO), any(Recipient[].class));
}
Also used : Message(com.fsck.k9.mail.Message) Test(org.junit.Test)

Example 8 with Recipient

use of com.fsck.k9.view.RecipientSelectView.Recipient in project k-9 by k9mail.

the class PgpMessageBuilderTest method buildEncrypt__shouldSucceed.

@Test
public void buildEncrypt__shouldSucceed() throws MessagingException {
    ComposeCryptoStatus cryptoStatus = cryptoStatusBuilder.setCryptoMode(CryptoMode.PRIVATE).setRecipients(Collections.singletonList(new Recipient("test", "test@example.org", "labru", -1, "key"))).build();
    pgpMessageBuilder.setCryptoStatus(cryptoStatus);
    ArgumentCaptor<Intent> capturedApiIntent = ArgumentCaptor.forClass(Intent.class);
    Intent returnIntent = new Intent();
    returnIntent.putExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_SUCCESS);
    when(openPgpApi.executeApi(capturedApiIntent.capture(), any(OpenPgpDataSource.class), any(OutputStream.class))).thenReturn(returnIntent);
    Callback mockCallback = mock(Callback.class);
    pgpMessageBuilder.buildAsync(mockCallback);
    Intent expectedApiIntent = new Intent(OpenPgpApi.ACTION_SIGN_AND_ENCRYPT);
    expectedApiIntent.putExtra(OpenPgpApi.EXTRA_SIGN_KEY_ID, TEST_SIGN_KEY_ID);
    expectedApiIntent.putExtra(OpenPgpApi.EXTRA_KEY_IDS, new long[] { TEST_SELF_ENCRYPT_KEY_ID });
    expectedApiIntent.putExtra(OpenPgpApi.EXTRA_REQUEST_ASCII_ARMOR, true);
    expectedApiIntent.putExtra(OpenPgpApi.EXTRA_ENCRYPT_OPPORTUNISTIC, false);
    expectedApiIntent.putExtra(OpenPgpApi.EXTRA_USER_IDS, cryptoStatus.getRecipientAddresses());
    assertIntentEqualsActionAndExtras(expectedApiIntent, capturedApiIntent.getValue());
    ArgumentCaptor<MimeMessage> captor = ArgumentCaptor.forClass(MimeMessage.class);
    verify(mockCallback).onMessageBuildSuccess(captor.capture(), eq(false));
    verifyNoMoreInteractions(mockCallback);
    MimeMessage message = captor.getValue();
    Assert.assertEquals("message must be multipart/encrypted", "multipart/encrypted", message.getMimeType());
    MimeMultipart multipart = (MimeMultipart) message.getBody();
    Assert.assertEquals("multipart/encrypted must consist of two parts", 2, multipart.getCount());
    BodyPart dummyBodyPart = multipart.getBodyPart(0);
    Assert.assertEquals("first part must be pgp encrypted dummy part", "application/pgp-encrypted", dummyBodyPart.getContentType());
    assertContentOfBodyPartEquals("content must match the supplied detached signature", dummyBodyPart, "Version: 1");
    BodyPart encryptedBodyPart = multipart.getBodyPart(1);
    Assert.assertEquals("second part must be octet-stream of encrypted data", "application/octet-stream; name=\"encrypted.asc\"", encryptedBodyPart.getContentType());
    Assert.assertTrue("message body must be BinaryTempFileBody", encryptedBodyPart.getBody() instanceof BinaryTempFileBody);
    Assert.assertEquals(MimeUtil.ENC_7BIT, ((BinaryTempFileBody) encryptedBodyPart.getBody()).getEncoding());
}
Also used : BodyPart(com.fsck.k9.mail.BodyPart) Callback(com.fsck.k9.message.MessageBuilder.Callback) BinaryTempFileBody(com.fsck.k9.mail.internet.BinaryTempFileBody) MimeMessage(com.fsck.k9.mail.internet.MimeMessage) MimeMultipart(com.fsck.k9.mail.internet.MimeMultipart) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) ComposeCryptoStatus(com.fsck.k9.activity.compose.ComposeCryptoStatus) Recipient(com.fsck.k9.view.RecipientSelectView.Recipient) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) OpenPgpDataSource(org.openintents.openpgp.util.OpenPgpApi.OpenPgpDataSource) Test(org.junit.Test)

Example 9 with Recipient

use of com.fsck.k9.view.RecipientSelectView.Recipient in project k-9 by k9mail.

the class PgpMessageBuilderTest method buildEncrypt__withInlineEnabled__shouldSucceed.

@Test
public void buildEncrypt__withInlineEnabled__shouldSucceed() throws MessagingException {
    ComposeCryptoStatus cryptoStatus = cryptoStatusBuilder.setCryptoMode(CryptoMode.PRIVATE).setRecipients(Collections.singletonList(new Recipient("test", "test@example.org", "labru", -1, "key"))).setEnablePgpInline(true).build();
    pgpMessageBuilder.setCryptoStatus(cryptoStatus);
    ArgumentCaptor<Intent> capturedApiIntent = ArgumentCaptor.forClass(Intent.class);
    Intent returnIntent = new Intent();
    returnIntent.putExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_SUCCESS);
    when(openPgpApi.executeApi(capturedApiIntent.capture(), any(OpenPgpDataSource.class), any(OutputStream.class))).thenReturn(returnIntent);
    Callback mockCallback = mock(Callback.class);
    pgpMessageBuilder.buildAsync(mockCallback);
    Intent expectedApiIntent = new Intent(OpenPgpApi.ACTION_SIGN_AND_ENCRYPT);
    expectedApiIntent.putExtra(OpenPgpApi.EXTRA_SIGN_KEY_ID, TEST_SIGN_KEY_ID);
    expectedApiIntent.putExtra(OpenPgpApi.EXTRA_KEY_IDS, new long[] { TEST_SELF_ENCRYPT_KEY_ID });
    expectedApiIntent.putExtra(OpenPgpApi.EXTRA_REQUEST_ASCII_ARMOR, true);
    expectedApiIntent.putExtra(OpenPgpApi.EXTRA_ENCRYPT_OPPORTUNISTIC, false);
    expectedApiIntent.putExtra(OpenPgpApi.EXTRA_USER_IDS, cryptoStatus.getRecipientAddresses());
    assertIntentEqualsActionAndExtras(expectedApiIntent, capturedApiIntent.getValue());
    ArgumentCaptor<MimeMessage> captor = ArgumentCaptor.forClass(MimeMessage.class);
    verify(mockCallback).onMessageBuildSuccess(captor.capture(), eq(false));
    verifyNoMoreInteractions(mockCallback);
    MimeMessage message = captor.getValue();
    Assert.assertEquals("text/plain", message.getMimeType());
    Assert.assertTrue("message body must be BinaryTempFileBody", message.getBody() instanceof BinaryTempFileBody);
    Assert.assertEquals(MimeUtil.ENC_7BIT, ((BinaryTempFileBody) message.getBody()).getEncoding());
}
Also used : Callback(com.fsck.k9.message.MessageBuilder.Callback) BinaryTempFileBody(com.fsck.k9.mail.internet.BinaryTempFileBody) MimeMessage(com.fsck.k9.mail.internet.MimeMessage) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) ComposeCryptoStatus(com.fsck.k9.activity.compose.ComposeCryptoStatus) Recipient(com.fsck.k9.view.RecipientSelectView.Recipient) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) OpenPgpDataSource(org.openintents.openpgp.util.OpenPgpApi.OpenPgpDataSource) Test(org.junit.Test)

Example 10 with Recipient

use of com.fsck.k9.view.RecipientSelectView.Recipient in project k-9 by k9mail.

the class RecipientSelectView method onRecipientChange.

@Override
public void onRecipientChange(Recipient recipientToReplace, Recipient alternateAddress) {
    alternatesPopup.dismiss();
    List<Recipient> currentRecipients = getObjects();
    int indexOfRecipient = currentRecipients.indexOf(recipientToReplace);
    if (indexOfRecipient == -1) {
        Timber.e("Tried to refresh invalid view token!");
        return;
    }
    Recipient currentRecipient = currentRecipients.get(indexOfRecipient);
    currentRecipient.address = alternateAddress.address;
    currentRecipient.addressLabel = alternateAddress.addressLabel;
    currentRecipient.cryptoStatus = alternateAddress.cryptoStatus;
    View recipientTokenView = getTokenViewForRecipient(currentRecipient);
    if (recipientTokenView == null) {
        Timber.e("Tried to refresh invalid view token!");
        return;
    }
    bindObjectView(currentRecipient, recipientTokenView);
    if (listener != null) {
        listener.onTokenChanged(currentRecipient);
    }
    invalidate();
}
Also used : Recipient(com.fsck.k9.view.RecipientSelectView.Recipient) ImageView(android.widget.ImageView) TokenCompleteTextView(com.tokenautocomplete.TokenCompleteTextView) View(android.view.View) TextView(android.widget.TextView) ListView(android.widget.ListView) SuppressLint(android.annotation.SuppressLint)

Aggregations

Recipient (com.fsck.k9.view.RecipientSelectView.Recipient)11 PendingIntent (android.app.PendingIntent)6 Intent (android.content.Intent)6 Test (org.junit.Test)6 Callback (com.fsck.k9.message.MessageBuilder.Callback)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 OutputStream (java.io.OutputStream)5 OpenPgpDataSource (org.openintents.openpgp.util.OpenPgpApi.OpenPgpDataSource)5 ComposeCryptoStatus (com.fsck.k9.activity.compose.ComposeCryptoStatus)4 MimeMessage (com.fsck.k9.mail.internet.MimeMessage)4 Address (com.fsck.k9.mail.Address)3 SuppressLint (android.annotation.SuppressLint)2 Uri (android.net.Uri)2 MessagingException (com.fsck.k9.mail.MessagingException)2 BinaryTempFileBody (com.fsck.k9.mail.internet.BinaryTempFileBody)2 Cursor (android.database.Cursor)1 Drawable (android.graphics.drawable.Drawable)1 NonNull (android.support.annotation.NonNull)1 View (android.view.View)1 ImageView (android.widget.ImageView)1