Search in sources :

Example 11 with Pop3Message

use of com.fsck.k9.mail.store.pop3.Pop3Message in project k-9 by k9mail.

the class Pop3Folder method setFlags.

public void setFlags(List<Pop3Message> messages, final Set<Flag> flags, boolean value) throws MessagingException {
    if (!value || !flags.contains(Flag.DELETED)) {
        /*
             * The only flagging we support is setting the Deleted flag.
             */
        return;
    }
    List<String> uids = new ArrayList<>();
    try {
        for (Pop3Message message : messages) {
            uids.add(message.getUid());
        }
        indexUids(uids);
    } catch (IOException ioe) {
        throw new MessagingException("Could not get message number for uid " + uids, ioe);
    }
    for (Pop3Message message : messages) {
        Integer msgNum = uidToMsgNumMap.get(message.getUid());
        if (msgNum == null) {
            throw new MessagingException("Could not delete message " + message.getUid() + " because no msgNum found; permanent error", true);
        }
        open();
        connection.executeSimpleCommand(String.format(DELE_COMMAND + " %s", msgNum));
    }
}
Also used : MessagingException(com.fsck.k9.mail.MessagingException) ArrayList(java.util.ArrayList) IOException(java.io.IOException)

Example 12 with Pop3Message

use of com.fsck.k9.mail.store.pop3.Pop3Message in project k-9 by k9mail.

the class Pop3FolderTest method fetch_withBodyProfile_setsContentOfMessage.

@Test
public void fetch_withBodyProfile_setsContentOfMessage() throws MessagingException, IOException {
    InputStream messageInputStream = new ByteArrayInputStream(("From: <adam@example.org>\r\n" + "To: <eva@example.org>\r\n" + "Subject: Testmail\r\n" + "MIME-Version: 1.0\r\n" + "Content-type: text/plain\r\n" + "Content-Transfer-Encoding: 7bit\r\n" + "\r\n" + "this is some test text.").getBytes());
    folder.open();
    List<Pop3Message> messageList = setupMessageFromServer();
    FetchProfile fetchProfile = new FetchProfile();
    fetchProfile.add(Item.BODY);
    when(mockConnection.readLine()).thenReturn("1 100").thenReturn(".");
    when(mockConnection.getInputStream()).thenReturn(messageInputStream);
    folder.fetch(messageList, fetchProfile, mockListener, MAX_DOWNLOAD_SIZE);
    ByteArrayOutputStream bodyData = new ByteArrayOutputStream();
    messageList.get(0).getBody().writeTo(bodyData);
    assertEquals("this is some test text.", new String(bodyData.toByteArray(), "UTF-8"));
}
Also used : FetchProfile(com.fsck.k9.mail.FetchProfile) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)6 Pop3Message (com.fsck.k9.mail.store.pop3.Pop3Message)5 FetchProfile (com.fsck.k9.mail.FetchProfile)4 MessagingException (com.fsck.k9.mail.MessagingException)4 Date (java.util.Date)3 AuthenticationFailedException (com.fsck.k9.mail.AuthenticationFailedException)2 Pop3Folder (com.fsck.k9.mail.store.pop3.Pop3Folder)2 Pop3Message (com.zimbra.cs.pop3.Pop3Message)2 IOException (java.io.IOException)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Test (org.junit.Test)2 SuppressLint (android.annotation.SuppressLint)1 BackendFolder (com.fsck.k9.backend.api.BackendFolder)1 MoreMessages (com.fsck.k9.backend.api.BackendFolder.MoreMessages)1 Flag (com.fsck.k9.mail.Flag)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 ZFolder (com.zimbra.client.ZFolder)1 DbConnection (com.zimbra.cs.db.DbPool.DbConnection)1 Folder (com.zimbra.cs.mailbox.Folder)1 TargetConstraint (com.zimbra.cs.mailbox.MailItem.TargetConstraint)1