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

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 something like below (most of the stuffs taken
from the attachments example):

...
@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;
            }
        }
...

If I send an email with some attachments, this code works perfectly fine
when I execute it via Netbeans. But, attachments.size() returns 0 for the
same code and same email inside Karaf.

Do I need to configure something specific for this?

Any inputs on this would be helpful.

Thanks,
Cooshal.

Reply via email to