Search in sources :

Example 6 with Address

use of com.fsck.k9.mail.Address in project k-9 by k9mail.

the class NotificationContentCreatorTest method createFakeLocalMessage.

private LocalMessage createFakeLocalMessage(MessageReference messageReference) throws Exception {
    LocalMessage message = mock(LocalMessage.class);
    when(message.makeMessageReference()).thenReturn(messageReference);
    when(message.getPreviewType()).thenReturn(PreviewType.TEXT);
    when(message.getPreview()).thenReturn(PREVIEW);
    when(message.getSubject()).thenReturn(SUBJECT);
    when(message.getFrom()).thenReturn(new Address[] { new Address(SENDER_ADDRESS, SENDER_NAME) });
    when(message.getRecipients(RecipientType.TO)).thenReturn(new Address[] { new Address(RECIPIENT_ADDRESS, RECIPIENT_NAME) });
    return message;
}
Also used : LocalMessage(com.fsck.k9.mailstore.LocalMessage) Address(com.fsck.k9.mail.Address)

Example 7 with Address

use of com.fsck.k9.mail.Address in project k-9 by k9mail.

the class ImapConnection method connect.

private Socket connect() throws GeneralSecurityException, MessagingException, IOException {
    Exception connectException = null;
    InetAddress[] inetAddresses = InetAddress.getAllByName(settings.getHost());
    for (InetAddress address : inetAddresses) {
        try {
            return connectToAddress(address);
        } catch (IOException e) {
            Log.w(LOG_TAG, "Could not connect to " + address, e);
            connectException = e;
        }
    }
    throw new MessagingException("Cannot connect to host", connectException);
}
Also used : MessagingException(com.fsck.k9.mail.MessagingException) IOException(java.io.IOException) InetAddress(java.net.InetAddress) CertificateValidationException(com.fsck.k9.mail.CertificateValidationException) GeneralSecurityException(java.security.GeneralSecurityException) KeyManagementException(java.security.KeyManagementException) SSLException(javax.net.ssl.SSLException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) SocketException(java.net.SocketException) ConnectException(java.net.ConnectException) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException) MessagingException(com.fsck.k9.mail.MessagingException) AuthenticationFailedException(com.fsck.k9.mail.AuthenticationFailedException)

Example 8 with Address

use of com.fsck.k9.mail.Address in project k-9 by k9mail.

the class SettingsExporter method writeIdentity.

private static void writeIdentity(XmlSerializer serializer, String accountUuid, String identity, Map<String, Object> prefs) throws IOException {
    serializer.startTag(null, IDENTITY_ELEMENT);
    String prefix = accountUuid + ".";
    String suffix = "." + identity;
    // Write name belonging to the identity
    String name = (String) prefs.get(prefix + Account.IDENTITY_NAME_KEY + suffix);
    serializer.startTag(null, NAME_ELEMENT);
    serializer.text(name);
    serializer.endTag(null, NAME_ELEMENT);
    // Write email address belonging to the identity
    String email = (String) prefs.get(prefix + Account.IDENTITY_EMAIL_KEY + suffix);
    serializer.startTag(null, EMAIL_ELEMENT);
    serializer.text(email);
    serializer.endTag(null, EMAIL_ELEMENT);
    // Write identity description
    String description = (String) prefs.get(prefix + Account.IDENTITY_DESCRIPTION_KEY + suffix);
    if (description != null) {
        serializer.startTag(null, DESCRIPTION_ELEMENT);
        serializer.text(description);
        serializer.endTag(null, DESCRIPTION_ELEMENT);
    }
    // Write identity settings
    serializer.startTag(null, SETTINGS_ELEMENT);
    for (Map.Entry<String, Object> entry : prefs.entrySet()) {
        String key = entry.getKey();
        String valueString = entry.getValue().toString();
        String[] comps = key.split("\\.");
        if (comps.length < 3) {
            // Skip non-identity config entries
            continue;
        }
        String keyUuid = comps[0];
        String identityKey = comps[1];
        String identityIndex = comps[2];
        if (!keyUuid.equals(accountUuid) || !identityIndex.equals(identity)) {
            // Skip entries that belong to another identity
            continue;
        }
        TreeMap<Integer, SettingsDescription> versionedSetting = IdentitySettings.SETTINGS.get(identityKey);
        if (versionedSetting != null) {
            Integer highestVersion = versionedSetting.lastKey();
            SettingsDescription setting = versionedSetting.get(highestVersion);
            if (setting != null) {
                // Only write settings that have an entry in IdentitySettings.SETTINGS
                try {
                    writeKeyAndPrettyValueFromSetting(serializer, identityKey, setting, valueString);
                } catch (InvalidSettingValueException e) {
                    Timber.w("Identity setting \"%s\" has invalid value \"%s\" in preference storage. " + "This shouldn't happen!", identityKey, valueString);
                }
            }
        }
    }
    serializer.endTag(null, SETTINGS_ELEMENT);
    serializer.endTag(null, IDENTITY_ELEMENT);
}
Also used : SettingsDescription(com.fsck.k9.preferences.Settings.SettingsDescription) InvalidSettingValueException(com.fsck.k9.preferences.Settings.InvalidSettingValueException) Map(java.util.Map) TreeMap(java.util.TreeMap)

Example 9 with Address

use of com.fsck.k9.mail.Address in project k-9 by k9mail.

the class NotificationContentCreator method getMessageSender.

private String getMessageSender(Account account, Message message) {
    boolean isSelf = false;
    final Contacts contacts = K9.showContactName() ? Contacts.getInstance(context) : null;
    final Address[] fromAddresses = message.getFrom();
    if (fromAddresses != null) {
        isSelf = account.isAnIdentity(fromAddresses);
        if (!isSelf && fromAddresses.length > 0) {
            return MessageHelper.toFriendly(fromAddresses[0], contacts).toString();
        }
    }
    if (isSelf) {
        // show To: if the message was sent from me
        Address[] recipients = message.getRecipients(Message.RecipientType.TO);
        if (recipients != null && recipients.length > 0) {
            return context.getString(R.string.message_to_fmt, MessageHelper.toFriendly(recipients[0], contacts).toString());
        }
    }
    return null;
}
Also used : Contacts(com.fsck.k9.helper.Contacts) Address(com.fsck.k9.mail.Address)

Example 10 with Address

use of com.fsck.k9.mail.Address in project k-9 by k9mail.

the class MessageHeader method onAddAddressesToClipboard.

private void onAddAddressesToClipboard(Address[] addresses) {
    String addressList = Address.toString(addresses);
    ClipboardManager clipboardManager = ClipboardManager.getInstance(mContext);
    clipboardManager.setText("addresses", addressList);
    Toast.makeText(mContext, createMessage(addresses.length), Toast.LENGTH_LONG).show();
}
Also used : ClipboardManager(com.fsck.k9.helper.ClipboardManager) SpannableString(android.text.SpannableString)

Aggregations

Address (com.fsck.k9.mail.Address)72 Test (org.junit.Test)40 Uri (android.net.Uri)13 RobolectricTest (com.fsck.k9.RobolectricTest)12 Message (com.fsck.k9.mail.Message)10 Date (java.util.Date)8 MimeMessage (com.fsck.k9.mail.internet.MimeMessage)7 ArrayList (java.util.ArrayList)7 MessagingException (com.fsck.k9.mail.MessagingException)6 Contacts (com.fsck.k9.helper.Contacts)5 Recipient (com.fsck.k9.view.RecipientSelectView.Recipient)5 AddressStyle (com.zegoggles.smssync.preferences.AddressStyle)5 IOException (java.io.IOException)5 Intent (android.content.Intent)4 Cursor (android.database.Cursor)4 MatrixCursor (android.database.MatrixCursor)4 AuthenticationFailedException (com.fsck.k9.mail.AuthenticationFailedException)4 CertificateValidationException (com.fsck.k9.mail.CertificateValidationException)4 TextBody (com.fsck.k9.mail.internet.TextBody)4 SpannableString (android.text.SpannableString)3