camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Claus Ibsen <claus.ib...@gmail.com>
Subject Re: Camel Mail issue with unsupported charset
Date Thu, 05 Nov 2009 05:36:10 GMT
On Thu, Nov 5, 2009 at 12:50 AM, dcheckoway <dcheckoway@gmail.com> wrote:
>
> Claus, I'm not a contributor on the Camel project, but here's what I would
> advocate trying in MailBinding.java, expanding the meaning of
> "ignoreUnsupportedCharset" a bit:
>
>    public Object extractBodyFromMail(Exchange exchange, Message message) {
>        return extractBodyFromMail(exchange, message, false);
>    }
>
>    private Object extractBodyFromMail(Exchange exchange, Message message,
> boolean isSecondAttempt) {
>        try {
>            return message.getContent();
>        } catch (Exception e) {
>            if (!isSecondAttempt &&
>                (e instanceof java.io.UnsupportedEncodingException ||
>                 (e.getCause() != null &&
>                  e.getCause() instanceof
> java.io.UnsupportedEncodingException)) &&
>                configuration.isIgnoreUnsupportedCharset()) {
>                // The charset is unsupported, but we've been configured to
>                // ingore that condition.  Let's at least attempt to rewrite
>                // the Content-Type header and omit the unsupported charset.
>                // This may wreak havoc down the line, but it's better than
>                // Camel just bailing on this exchange, and ending up
> retrying
>                // this same message over and over, and failing every
> time...
>                String contentType = message.getContentType();
>                if (contentType != null) {
>                    // Wipe out the charset=... from the Content-Type header
>                    contentType =
> contentType.replaceAll("\\s*charset=[^;\\s]+", "");
>                    part.setHeader("Content-Type", contentType);
>                    // Try again...pass isSecondAttempt=true this time
>                    return extractBodyFromMail(exchange, message, true);
>                }
>            }
>            else {
>                throw new RuntimeCamelException("Failed to extract body due
> to: " + e.getMessage()
>                                                + ". Exchange:
" + exchange
> + ". Message: " + message, e);
>            }
>        }
>    }
>
> What do you think?
>

Yeah we could add such a work around.
Does it fix you issue when you manually remove that charset from the
header and can you read it on the 2nd attempt then?

And btw you are a Camel contributor :) And kind of activity is
measured for your metrics.
See some of the Apache blogs about how that works :)

Please create a JIRA ticket and submit your patch. And if possible an
unit test that demonstrates this if that is possible.

And Camel have some code to extract the exception from the hierarchy a
bit nicer and cleaner.

UnsupportedEncodingException uce =
ObjectHelper.getException(UnsupportedEncodingException.class, e);
if (uce != null) {
   // okay there was such kind of exception
}



>
>
> Claus Ibsen-2 wrote:
>>
>> On Wed, Nov 4, 2009 at 7:24 PM, dcheckoway <dcheckoway@gmail.com> wrote:
>>>
>>> Is there any way to "intercept" the raw mail message content before it
>>> gets
>>> passed to the java mail API?  I would be happy to manually munge the
>>> Content-Type header if I detect one of the known-to-be-funky charsets in
>>> there.
>>>
>>
>> You can use a custom MailBinding class, e.g. extending the on in
>> camel-maill.
>>
>
> --
> View this message in context: http://old.nabble.com/Camel-Mail-issue-with-unsupported-charset-tp24755585p26206832.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>



-- 
Claus Ibsen
Apache Camel Committer

Author of Camel in Action: http://www.manning.com/ibsen/
Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus

Mime
View raw message