karaf-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Kushal Gautam <kushal.gau...@gmail.com>
Subject camel-mail does not retrieve email attachments only in Karaf
Date Thu, 04 Jun 2020 09:52:01 GMT
Hi:

currently, I am using camel-mail to fetch mails via IMAP.

The route is pretty simple and looks like:

from("imaps://{{IMAP_SERVER_URL}}"
                + "?username={{IMAP_EMAIL_USER}}"
                + "&password={{IMAP_EMAIL_PASS}}"
                + "&unseen=true"
                + "&delete=false"
                + "&initialDelay=100"
                + "&delay={{IMAP_POLL_DURATION}}")
.....

My custom processor looks like this (nothing fancy)

@Override
    public void process(Exchange exchange) throws Exception {

        exchange.getIn().setHeader("HAS_ATTACHMENTS", false);

        Map<String, DataHandler> attachments =
exchange.getIn().getAttachments();

        if (attachments.size() > 0) {
            for (String name : attachments.keySet()) {
                DataHandler dh = attachments.get(name);
                // get the file name
                String filename = dh.getName();

                System.out.println(filename);

                // check if the attachment is an xml file
                // if not continue to another attachment
                if(!filename.endsWith(".xml")) {
                    continue;
                }

                System.out.println("email has an xml attachment");

                // get the content and convert it to byte[]
                byte[] data = exchange
                        .getContext()
                        .getTypeConverter()
                        .convertTo(byte[].class, dh.getInputStream());

                exchange.getIn().setHeader("FILE_NAME", filename);
                exchange.getIn().setHeader("HAS_ATTACHMENTS", true);

                exchange.getIn().setBody(data);
                break;
            }
        }

This code setup works perfectly fine if I execute it via Netbeans. But,
attachments.size() returns 0 for the same code and email inside Karaf.

Camel Version: 2.20.3
Java: Open JDK 1.8.0_242
Karaf: 4.2.0

Do I need to configure something specific for this?

Any inputs on this would be helpful.

Thanks,
Cooshal.

Mime
View raw message