Repository: Stirling-Tools/Stirling-PDF
File: common/src/main/java/stirling/software/common/util/EmlToPdf.java (Java)

Code before:
        static final long BYTES_IN_GB = BYTES_IN_MB * 1024L;

        private FileSizeConstants() {}
    }

    // Cached Jakarta Mail availability check
    private static Boolean jakartaMailAvailable = null;

    private static boolean isJakartaMailAvailable() {
        if (jakartaMailAvailable == null) {
            try {
                // Check for core Jakarta Mail classes
                Class.forName("jakarta.mail.internet.MimeMessage");
                Class.forName("jakarta.mail.Session");
                Class.forName("jakarta.mail.internet.MimeUtility");
                Class.forName("jakarta.mail.internet.MimePart");
                Class.forName("jakarta.mail.internet.MimeMultipart");
                Class.forName("jakarta.mail.Multipart");
                Class.forName("jakarta.mail.Part");

                jakartaMailAvailable = true;
                log.debug("Jakarta Mail libraries are available");
            } catch (ClassNotFoundException e) {
                // In Docker/production environments, if we detect we're in a containerized
                // environment
                String dockerEnv = System.getenv("DOCKER_ENABLE_SECURITY");
                String disableFeatures = System.getenv("DISABLE_ADDITIONAL_FEATURES");

                if (dockerEnv != null || disableFeatures != null) {
                    jakartaMailAvailable = false;
                    log.warn("Jakarta Mail not found but in Docker environment");
                } else {
                    jakartaMailAvailable = false;
                    log.debug("Jakarta Mail libraries are not available, using basic parsing");
                }
            }
        }
        return jakartaMailAvailable;
    }

    public static String convertEmlToHtml(byte[] emlBytes, EmlToPdfRequest request)
            throws IOException {
        validateEmlInput(emlBytes);

        if (isJakartaMailAvailable()) {
            return convertEmlToHtmlAdvanced(emlBytes, request);
        } else {
            return convertEmlToHtmlBasic(emlBytes, request);
        }
    }


Review comment (suggestion):
Better to check using bean (or local similar to)
 @Bean(name = "RunningInDocker")
    public boolean runningInDocker() {
        return Files.exists(Paths.get("/.dockerenv"));
    }
 @Bean(name = "machineType")
    public String determineMachineType() {
        try {
            boolean isDocker = runningInDocker();
            boolean isKubernetes = System.getenv("KUBERNETES_SERVICE_HOST") != null;
            boolean isBrowserOpen = "true".equalsIgnoreCase(env.getProperty("BROWSER_OPEN"));

            if (isKubernetes) {
                return "Kubernetes";
            } else if (isDocker) {
                return "Docker";
            } else if (isBrowserOpen) {
                String os = System.getProperty("os.name").toLowerCase(Locale.ROOT);
                if (os.contains("win")) {
                    return "Client-windows";
                } else if (os.contains("mac")) {
                    return "Client-mac";
                } else {
                    return "Client-unix";
                }
            } else {
                return "Server-jar";
            }
        } catch (Exception e) {
            return "Unknown";
        }
    }
    
    

Code after:
        static final long BYTES_IN_GB = BYTES_IN_MB * 1024L;

        private FileSizeConstants() {}
    }

    // Cached Jakarta Mail availability check
    private static Boolean jakartaMailAvailable = null;

    private static boolean isJakartaMailAvailable() {
        if (jakartaMailAvailable == null) {
            try {
                // Check for core Jakarta Mail classes
                Class.forName("jakarta.mail.internet.MimeMessage");
                Class.forName("jakarta.mail.Session");
                Class.forName("jakarta.mail.internet.MimeUtility");
                Class.forName("jakarta.mail.internet.MimePart");
                Class.forName("jakarta.mail.internet.MimeMultipart");
                Class.forName("jakarta.mail.Multipart");
                Class.forName("jakarta.mail.Part");

                jakartaMailAvailable = true;
                log.debug("Jakarta Mail libraries are available");
            } catch (ClassNotFoundException e) {
                jakartaMailAvailable = false;
                log.debug("Jakarta Mail libraries are not available, using basic parsing");
            }
        }
        return jakartaMailAvailable;
    }

    public static String convertEmlToHtml(byte[] emlBytes, EmlToPdfRequest request)
            throws IOException {
        validateEmlInput(emlBytes);

        if (isJakartaMailAvailable()) {
            return convertEmlToHtmlAdvanced(emlBytes, request);
        } else {
            return convertEmlToHtmlBasic(emlBytes, request);
        }
    }

    public static byte[] convertEmlToPdf(
            String weasyprintPath,
            EmlToPdfRequest request,
            byte[] emlBytes,
            String fileName,
            boolean disableSanitize,
            stirling.software.common.service.CustomPDFDocumentFactory pdfDocumentFactory)
            throws IOException, InterruptedException {

        validateEmlInput(emlBytes);