Search in sources :

Example 76 with MessagingException

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

the class MessageCompose method processMessageToForward.

private void processMessageToForward(MessageViewInfo messageViewInfo, boolean asAttachment) throws MessagingException {
    Message message = messageViewInfo.message;
    String subject = messageViewInfo.subject;
    if (subject != null && !subject.toLowerCase(Locale.US).startsWith("fwd:")) {
        subjectView.setText("Fwd: " + subject);
    } else {
        subjectView.setText(subject);
    }
    // even if there are multiple references.
    if (!TextUtils.isEmpty(message.getMessageId())) {
        repliedToMessageId = message.getMessageId();
        referencedMessageIds = repliedToMessageId;
    } else {
        Timber.d("could not get Message-ID.");
    }
    // Quote the message and setup the UI.
    if (asAttachment) {
        attachmentPresenter.processMessageToForwardAsAttachment(messageViewInfo);
    } else {
        quotedMessagePresenter.processMessageToForward(messageViewInfo);
        attachmentPresenter.processMessageToForward(messageViewInfo);
    }
    setIdentityFromMessage(message);
}
Also used : LocalMessage(com.fsck.k9.mailstore.LocalMessage) MimeMessage(com.fsck.k9.mail.internet.MimeMessage) Message(com.fsck.k9.mail.Message)

Example 77 with MessagingException

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

the class MessageCompose method processMessageToReplyTo.

private void processMessageToReplyTo(MessageViewInfo messageViewInfo) throws MessagingException {
    Message message = messageViewInfo.message;
    if (messageViewInfo.subject != null) {
        final String subject = PREFIX.matcher(messageViewInfo.subject).replaceFirst("");
        if (!subject.toLowerCase(Locale.US).startsWith("re:")) {
            subjectView.setText("Re: " + subject);
        } else {
            subjectView.setText(subject);
        }
    } else {
        subjectView.setText("");
    }
    /*
         * If a reply-to was included with the message use that, otherwise use the from
         * or sender address.
         */
    boolean isReplyAll = action == Action.REPLY_ALL;
    recipientPresenter.initFromReplyToMessage(message, isReplyAll);
    if (message.getMessageId() != null && message.getMessageId().length() > 0) {
        repliedToMessageId = message.getMessageId();
        String[] refs = message.getReferences();
        if (refs != null && refs.length > 0) {
            referencedMessageIds = TextUtils.join("", refs) + " " + repliedToMessageId;
        } else {
            referencedMessageIds = repliedToMessageId;
        }
    } else {
        Timber.d("could not get Message-ID.");
    }
    // Quote the message and setup the UI.
    quotedMessagePresenter.initFromReplyToMessage(messageViewInfo, action);
    if (action == Action.REPLY || action == Action.REPLY_ALL) {
        setIdentityFromMessage(message);
    }
}
Also used : LocalMessage(com.fsck.k9.mailstore.LocalMessage) MimeMessage(com.fsck.k9.mail.internet.MimeMessage) Message(com.fsck.k9.mail.Message)

Example 78 with MessagingException

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

the class RealImapConnectionTest method open_authPlainWithLoginDisabled_shouldThrow.

@Test
public void open_authPlainWithLoginDisabled_shouldThrow() throws Exception {
    settings.setAuthType(AuthType.PLAIN);
    MockImapServer server = new MockImapServer();
    preAuthenticationDialog(server, "LOGINDISABLED");
    ImapConnection imapConnection = startServerAndCreateImapConnection(server);
    try {
        imapConnection.open();
        fail("Expected exception");
    } catch (MessagingException e) {
        assertEquals("Server doesn't support unencrypted passwords using AUTH=PLAIN and LOGIN is disabled.", e.getMessage());
    }
    server.verifyConnectionClosed();
    server.verifyInteractionCompleted();
}
Also used : MessagingException(com.fsck.k9.mail.MessagingException) MockImapServer(com.fsck.k9.mail.store.imap.mockserver.MockImapServer) XOAuth2ChallengeParserTest(com.fsck.k9.mail.XOAuth2ChallengeParserTest) Test(org.junit.Test)

Example 79 with MessagingException

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

the class RealImapConnectionTest method open_authCramMd5WithoutAuthCramMd5Capability_shouldThrow.

@Test
public void open_authCramMd5WithoutAuthCramMd5Capability_shouldThrow() throws Exception {
    settings.setAuthType(AuthType.CRAM_MD5);
    MockImapServer server = new MockImapServer();
    preAuthenticationDialog(server, "AUTH=PLAIN");
    ImapConnection imapConnection = startServerAndCreateImapConnection(server);
    try {
        imapConnection.open();
        fail("Expected exception");
    } catch (MessagingException e) {
        assertEquals("Server doesn't support encrypted passwords using CRAM-MD5.", e.getMessage());
    }
    server.verifyConnectionClosed();
    server.verifyInteractionCompleted();
}
Also used : MessagingException(com.fsck.k9.mail.MessagingException) MockImapServer(com.fsck.k9.mail.store.imap.mockserver.MockImapServer) XOAuth2ChallengeParserTest(com.fsck.k9.mail.XOAuth2ChallengeParserTest) Test(org.junit.Test)

Example 80 with MessagingException

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

the class RealImapStore method listFolders.

private List<FolderListItem> listFolders(ImapConnection connection, boolean subscribedOnly) throws IOException, MessagingException {
    String commandFormat;
    if (subscribedOnly) {
        commandFormat = "LSUB \"\" %s";
    } else if (connection.hasCapability(Capabilities.SPECIAL_USE) && connection.hasCapability(Capabilities.LIST_EXTENDED)) {
        commandFormat = "LIST \"\" %s RETURN (SPECIAL-USE)";
    } else {
        commandFormat = "LIST \"\" %s";
    }
    String encodedListPrefix = ImapUtility.encodeString(getCombinedPrefix() + "*");
    List<ImapResponse> responses = connection.executeSimpleCommand(String.format(commandFormat, encodedListPrefix));
    List<ListResponse> listResponses = (subscribedOnly) ? ListResponse.parseLsub(responses) : ListResponse.parseList(responses);
    Map<String, FolderListItem> folderMap = new HashMap<>(listResponses.size());
    for (ListResponse listResponse : listResponses) {
        String serverId = listResponse.getName();
        if (pathDelimiter == null) {
            pathDelimiter = listResponse.getHierarchyDelimiter();
            combinedPrefix = null;
        }
        if (RealImapFolder.INBOX.equalsIgnoreCase(serverId)) {
            continue;
        } else if (listResponse.hasAttribute("\\NoSelect")) {
            continue;
        }
        String name = getFolderDisplayName(serverId);
        String oldServerId = getOldServerId(serverId);
        FolderType type;
        if (listResponse.hasAttribute("\\Archive") || listResponse.hasAttribute("\\All")) {
            type = FolderType.ARCHIVE;
        } else if (listResponse.hasAttribute("\\Drafts")) {
            type = FolderType.DRAFTS;
        } else if (listResponse.hasAttribute("\\Sent")) {
            type = FolderType.SENT;
        } else if (listResponse.hasAttribute("\\Junk")) {
            type = FolderType.SPAM;
        } else if (listResponse.hasAttribute("\\Trash")) {
            type = FolderType.TRASH;
        } else {
            type = FolderType.REGULAR;
        }
        FolderListItem existingItem = folderMap.get(serverId);
        if (existingItem == null || existingItem.getType() == FolderType.REGULAR) {
            folderMap.put(serverId, new FolderListItem(serverId, name, type, oldServerId));
        }
    }
    List<FolderListItem> folders = new ArrayList<>(folderMap.size() + 1);
    folders.add(new FolderListItem(RealImapFolder.INBOX, RealImapFolder.INBOX, FolderType.INBOX, RealImapFolder.INBOX));
    folders.addAll(folderMap.values());
    return folders;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) FolderType(com.fsck.k9.mail.FolderType)

Aggregations

MessagingException (com.fsck.k9.mail.MessagingException)159 Test (org.junit.Test)73 MimeMessage (com.fsck.k9.mail.internet.MimeMessage)52 LocalFolder (com.fsck.k9.mailstore.LocalFolder)49 LocalStore (com.fsck.k9.mailstore.LocalStore)49 ArrayList (java.util.ArrayList)49 Message (com.fsck.k9.mail.Message)44 LocalMessage (com.fsck.k9.mailstore.LocalMessage)42 IOException (java.io.IOException)42 FetchProfile (com.fsck.k9.mail.FetchProfile)30 MimeBodyPart (com.fsck.k9.mail.internet.MimeBodyPart)28 ByteArrayOutputStream (java.io.ByteArrayOutputStream)27 AuthenticationFailedException (com.fsck.k9.mail.AuthenticationFailedException)26 BodyPart (com.fsck.k9.mail.BodyPart)23 Part (com.fsck.k9.mail.Part)22 Account (com.fsck.k9.Account)21 Body (com.fsck.k9.mail.Body)21 TextBody (com.fsck.k9.mail.internet.TextBody)21 Date (java.util.Date)20 MimeMultipart (com.fsck.k9.mail.internet.MimeMultipart)18