Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit a479c9dd authored by Wolf-Martell Montwé's avatar Wolf-Martell Montwé Committed by GitHub
Browse files

Merge pull request #9289 from shamim-emon/fix-issue-9288

Convert FetchPartCallback class from java to kotlin
parents d284d080 91a3839a
Loading
Loading
Loading
Loading
+0 −34
Original line number Diff line number Diff line
package com.fsck.k9.mail.store.imap;


import java.io.IOException;

import com.fsck.k9.mail.BodyFactory;
import com.fsck.k9.mail.Part;
import com.fsck.k9.mail.filter.FixedLengthInputStream;
import com.fsck.k9.mail.internet.MimeHeader;


class FetchPartCallback implements ImapResponseCallback {
    private final Part part;
    private final BodyFactory bodyFactory;


    FetchPartCallback(Part part, BodyFactory bodyFactory) {
        this.part = part;
        this.bodyFactory = bodyFactory;
    }

    @Override
    public Object foundLiteral(ImapResponse response, FixedLengthInputStream literal) throws IOException {
        if (response.getTag() == null && ImapResponseParser.equalsIgnoreCase(response.get(1), "FETCH")) {
            //TODO: check for correct UID

            String contentTransferEncoding = part.getHeader(MimeHeader.HEADER_CONTENT_TRANSFER_ENCODING)[0];
            String contentType = part.getHeader(MimeHeader.HEADER_CONTENT_TYPE)[0];

            return bodyFactory.createBody(contentTransferEncoding, contentType, literal);
        }
        return null;
    }
}
+23 −0
Original line number Diff line number Diff line
package com.fsck.k9.mail.store.imap

import com.fsck.k9.mail.BodyFactory
import com.fsck.k9.mail.Part
import com.fsck.k9.mail.filter.FixedLengthInputStream
import com.fsck.k9.mail.internet.MimeHeader
import java.io.IOException

internal class FetchPartCallback(private val part: Part, private val bodyFactory: BodyFactory) :
    ImapResponseCallback {
    @Throws(IOException::class)
    override fun foundLiteral(response: ImapResponse, literal: FixedLengthInputStream): Any? {
        if (response.tag == null && ImapResponseParser.equalsIgnoreCase(response[1], "FETCH")) {
            // TODO: check for correct UID

            val contentTransferEncoding = part.getHeader(MimeHeader.HEADER_CONTENT_TRANSFER_ENCODING)[0]
            val contentType = part.getHeader(MimeHeader.HEADER_CONTENT_TYPE)[0]

            return bodyFactory.createBody(contentTransferEncoding, contentType, literal)
        }
        return null
    }
}