I recently changed the dependency
<dependency>
    <groupId>javax.mail</groupId>
    <artifactId>mail</artifactId>
    <version>1.4</version>
</dependency>

to
<dependency>
    <groupId>javax.mail</groupId>
    <artifactId>javax.mail-api</artifactId>
    <version>1.6.0</version>
</dependency>

because Java 8 doesn't support 1.4 version as it uses TLS 1.0.
After changing the dependency this code starts giving error.
Error code:
if (p.getContentType().contains("image/")) {
    File f = new File("image" + new Date().getTime() + ".jpg");
    DataOutputStream output = new DataOutputStream(
            new BufferedOutputStream(new FileOutputStream(f)));
    
    com.sun.mail.util.BASE64DecoderStream test = (com.sun.mail.util.BASE64DecoderStream) p
            .getContent();
    byte[] buffer = new byte[1024];
    int bytesRead;
    while ((bytesRead = test.read(buffer)) != -1) {
        output.write(buffer, 0, bytesRead);
    }

Eclipse suggestion error:
Multiple markers at this line
    - com.sun.mail.util.BASE64DecoderStream cannot be resolved to a type
    - com.sun.mail.util.BASE64DecoderStream cannot be resolved to a type


"BASE64DecoderStream" gives error for javax-mail dependency
You're using the wrong dependency. You have only added the JakartaMail API. You should use the JakartaMail 1.6.x implementation:
<dependency>
    <groupId>com.sun.mail</groupId>
    <artifactId>jakarta.mail</artifactId>
    <version>1.6.7</version>
</dependency>

This dependency does include com.sun.mail.util.BASE64DecoderStream.
As an aside, instead of what you're doing now (using getContent() and casting to an implementation-specific class), you could also use Part.getInputStream():
try (var in = p.getInputStream()) {
    in.transferTo(output);
}

Also, your use of DataOutputStream is suspect, as you don't seem to be using any DataOutputStream specific methods, so using the BufferedOutputStream directly should be sufficient.
