You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Claus Ibsen <cl...@gmail.com> on 2018/02/01 17:00:34 UTC

Re: Rép. : Re: Convertbody with dynamic Charset

Its typically only the message body. But some type converters may use
this charset value from the exchange when they convert. But its not so
common to have headers in different encodings.

But give it some test on your applications and see how it goes

On Fri, Jan 12, 2018 at 6:56 PM, Daniel Langevin
<da...@shq.gouv.qc.ca> wrote:
> Thanks.
>
> Does it affect all the exchange content. ?
>
> like
> Body value and Headers value
>
>
> Daniel
>
>
>
>
>
>
>>>> Claus Ibsen <cl...@gmail.com> 2018-01-12 11:03 >>>
> If you want to set a dynamic charset, then you can set it as exchange
> property before calling convert body to
>
> <setProperty propertyName="Exchange.CHARSET_NAME">
>    <simple>${property.mailCharSet}</simple>
> </setProperty>
> <convertBody ...>
>
> On Fri, Jan 12, 2018 at 4:55 PM, Daniel Langevin
> <da...@shq.gouv.qc.ca> wrote:
>> Ok Thanks.
>> I know that way, but can't be Dynamic
>>
>>
>> Regards
>>
>> Daniel
>>
>>
>>
>>
>>
>>
>>>>> Claus Ibsen <cl...@gmail.com> 2018-01-12 10:51 >>>
>> You cannot make it as a dynamic value computed from each message,
> but
>> you can configure it externally using property placeholders. For the
>> latter read the documentation
>> http://camel.apache.org/using-propertyplaceholder.html
>>
>> On Fri, Jan 12, 2018 at 4:23 PM, Daniel Langevin
>> <da...@shq.gouv.qc.ca> wrote:
>>> Hi,
>>>
>>> i try to use convertBody to and pass the charset dynamically.
>>>
>>>
>>> i try:
>>> #1
>>> <setProperty propertyName="mailCharSet"><groovy> ...... retrieve
>> charSet BodyPart from mail</groovy></setProperty>
>>>  <convertBodyTo type="java.lang.String"
>> charset="${property.mailCharSet}"></convertBodyTo>
>>>
>>> but receive error
>>> Caused by: java.nio.charset.IllegalCharsetNameException:
>> ${property.mailCharSet}
>>>
>>> #2
>>> <setProperty propertyName="mailCharSet"><groovy> ...... retrieve
>> charSet BodyPart from mail</groovy></setProperty>
>>> <convertBodyTo type="java.lang.String"
>> charset="{{mailCharSet}}"></convertBodyTo>
>>>
>>> but receive error
>>> Caused by: java.lang.IllegalArgumentException: Property with key
>> [mailCharSet] not found in properties from text: {{mailCharSet}}
>>> ..... is searching  property key mailCharSet from my property
>> folder., but this one cannot be Dynamic !
>>>
>>> #3
>>> add this property key in my property file
>>> charset_UTF-8=utf-8
>>>
>>> <setProperty
>> propertyName="mailCharSet"><constant>UTF-8</constant></setProperty>
>>> <convertBodyTo type="java.lang.String"
>> charset="{{charset_${property.mailCharSet}}}"></convertBodyTo>
>>>
>>> but receive error
>>> Caused by: java.lang.IllegalArgumentException: Property with key
>> [charset_${property.mailCharSet] not found in properties from text:
>> {{charset_${property.mailCharSet}}}
>>> ... substitution doesn't work !!?!! it supposed to search
>> charset_UTF-8 into property folder !
>>>
>>> There is a way to achieve that ?  Someone have an idea !
>>>
>>>
>>> Daniel
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> "Le présent courriel peut contenir des renseignements confidentiels
>> et ne s'adresse qu'au destinataire dont le nom apparaît ci-dessus. Si
> ce
>> courriel vous est parvenu par mégarde, veuillez le supprimer et nous
> en
>> aviser aussitôt."
>>
>>
>>
>> --
>> Claus Ibsen
>> -----------------
>> http://davsclaus.com @davsclaus
>> Camel in Action 2: https://www.manning.com/ibsen2
>>
>>
>> "Le présent courriel peut contenir des renseignements confidentiels
> et ne s'adresse qu'au destinataire dont le nom apparaît ci-dessus. Si ce
> courriel vous est parvenu par mégarde, veuillez le supprimer et nous en
> aviser aussitôt."
>
>
>
> --
> Claus Ibsen
> -----------------
> http://davsclaus.com @davsclaus
> Camel in Action 2: https://www.manning.com/ibsen2
>
>
> "Le présent courriel peut contenir des renseignements confidentiels et ne s'adresse qu'au destinataire dont le nom apparaît ci-dessus. Si ce courriel vous est parvenu par mégarde, veuillez le supprimer et nous en aviser aussitôt."



-- 
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2

Re: Rép. : Re: Convertbody with dynamic Charset

Posted by Daniel Langevin <da...@shq.gouv.qc.ca>.
Hi,

in my application i got only one other header who can have special
character,
this header is Subject header from mail Component in receiving mode.

I already have to decode the content  of the Subject header in respect
of RFC 1342 rule
The containt can be :
Simple ASCII like:  Welcome Camel in Quebec
or Base64 like : =?UTF8-8?B?V2VsY29tZSBDYW1lbCBpbiBRdcOpYmVj?
or QuotedPrintabel like:
=?UTF-8?Q?Welcome=20Camel=20in=20Qu=C3=A9bec?=

So in this case it dont have any negative effect yet, using property
Exchange.CHARSET_NAME  in my test.


MAY BE INTERESTING FOR SOMEONE !

A) my sample Groovy code for decoding Base64 Subject in Mail receive

<setHeader headerName="SubjectDecode" >
<groovy>
subjectEncoding     =
request.headers['Subject'].replaceAll('(([^=]*)=\\?([^\\?]*)\\?([BbQq])\\?([^\\?]*)\\?=([^=]*))','$4')
<!-- B ou Q -->
subjectCharSet      =
request.headers['Subject'].replaceAll('(([^=]*)=\\?([^\\?]*)\\?([BbQq])\\?([^\\?]*)\\?=([^=]*))','$3')
subjectCharSetArray =
request.headers['Subject'].replaceAll('(([^=]*)=\\?([^\\?]*)\\?([BbQq])\\?([^\\?]*)\\?=([^=]*))','$3\n').tokenize('\n');
subjectArray =
request.headers['Subject'].replaceAll('(([^=]*)=\\?([^\\?]*)\\?([BbQq])\\?([^\\?]*)\\?=([^=]*))','$5\n').tokenize('\n');
zresult = '';
for(i = 0; i &lt; subjectEncoding.length(); i++) {
     zresult = zresult + new
String(org.apache.commons.codec.binary.Base64.decodeBase64(subjectArray[i]),subjectCharSetArray[i]);
}
result = zresult;
</groovy>
</setheader>


B) my sample Groovy code for decoding QuotePrintable Subject in Mail
receive

<setHeader headerName="SubjectDecode" >
<groovy>
subjectEncoding     =
request.headers['Subject'].replaceAll('(([^=]*)=\\?([^\\?]*)\\?([BbQq])\\?([^\\?]*)\\?=([^=]*))','$4')
<!-- B ou Q -->
subjectCharSet      =
request.headers['Subject'].replaceAll('(([^=]*)=\\?([^\\?]*)\\?([BbQq])\\?([^\\?]*)\\?=([^=]*))','$3')
zresult = '';
 zresult = new
String(org.apache.commons.codec.net.QuotedPrintableCodec.decodeQuotedPrintable(request.headers['Subject'].replaceAll('(([^=]*)=\\?([^\\?]*)\\?([BbQq])\\?([^\\?]*)\\?=([^=]*))','$5').getBytes()),subjectCharSet)}
result = zresult;
</groovy>
</setheader>

Hope it can help someone.

regards.



Daniel





>>> Claus Ibsen <cl...@gmail.com> 2018-02-01 12:00 >>>
Its typically only the message body. But some type converters may use
this charset value from the exchange when they convert. But its not so
common to have headers in different encodings.

But give it some test on your applications and see how it goes

On Fri, Jan 12, 2018 at 6:56 PM, Daniel Langevin
<da...@shq.gouv.qc.ca> wrote:
> Thanks.
>
> Does it affect all the exchange content. ?
>
> like
> Body value and Headers value
>
>
> Daniel
>
>
>
>
>
>
>>>> Claus Ibsen <cl...@gmail.com> 2018-01-12 11:03 >>>
> If you want to set a dynamic charset, then you can set it as
exchange
> property before calling convert body to
>
> <setProperty propertyName="Exchange.CHARSET_NAME">
>    <simple>${property.mailCharSet}</simple>
> </setProperty>
> <convertBody ...>
>
> On Fri, Jan 12, 2018 at 4:55 PM, Daniel Langevin
> <da...@shq.gouv.qc.ca> wrote:
>> Ok Thanks.
>> I know that way, but can't be Dynamic
>>
>>
>> Regards
>>
>> Daniel
>>
>>
>>
>>
>>
>>
>>>>> Claus Ibsen <cl...@gmail.com> 2018-01-12 10:51 >>>
>> You cannot make it as a dynamic value computed from each message,
> but
>> you can configure it externally using property placeholders. For
the
>> latter read the documentation
>> http://camel.apache.org/using-propertyplaceholder.html 
>>
>> On Fri, Jan 12, 2018 at 4:23 PM, Daniel Langevin
>> <da...@shq.gouv.qc.ca> wrote:
>>> Hi,
>>>
>>> i try to use convertBody to and pass the charset dynamically.
>>>
>>>
>>> i try:
>>> #1
>>> <setProperty propertyName="mailCharSet"><groovy> ...... retrieve
>> charSet BodyPart from mail</groovy></setProperty>
>>>  <convertBody
To type="java.lang.String"
>> charset="${property.mailCharSet}"></convertBodyTo>
>>>
>>> but receive error
>>> Caused by: java.nio.charset.IllegalCharsetNameException:
>> ${property.mailCharSet}
>>>
>>> #2
>>> <setProperty propertyName="mailCharSet"><groovy> ...... retrieve
>> charSet BodyPart from mail</groovy></setProperty>
>>> <convertBodyTo type="java.lang.String"
>> charset="{{mailCharSet}}"></convertBodyTo>
>>>
>>> but receive error
>>> Caused by: java.lang.IllegalArgumentException: Property with key
>> [mailCharSet] not found in properties from text: {{mailCharSet}}
>>> ..... is searching  property key mailCharSet from my property
>> folder., but this one cannot be Dynamic !
>>>
>>> #3
>>> add this property key in my property file
>>> charset_UTF-8=utf-8
>>>
>>> <setProperty
>> propertyName="mailCharSet"><constant>UTF-8</constant></setProperty>
>>> <convertBodyTo type="java.lang.String"
>> charset="{{charset_${property.mailCharSet}}}"></convertBodyTo>
>>>
>>> but receive error
>>> Caused by: java.lang.IllegalArgumentException: Property with key
>> [charset_${property.mailCharSet] not found in properties from text:
>> {{charset_${property.mailCharSet}}}
>>> ... substitution doesn't work !!?!! it supposed to search
>> charset_UTF-8 into property folder !
>>>
>>> There is a way to achieve that ?  Someone have an idea !
>>>
>>>
>>> Daniel
>>>
>>>
>>>
>>
>>
>> --
>> Claus Ibsen
>> -----------------
>> http://davsclaus.com @davsclaus
>> Camel in Action 2: https://www.manning.com/ibsen2 
>>
>>
>> "Le présent courriel peut contenir des renseignements confidentiels
> et ne s'adresse qu'au destinataire dont le nom apparaît ci-dessus. Si
ce
> courriel vous est parvenu par mégarde, veuillez le supprimer et nous
en
> aviser aussitôt."
>
>
>
> --
> Claus Ibsen
> -----------------
> http://davsclaus.com @davsclaus
> Camel in Action 2: https://www.manning.com/ibsen2 
>


-- 
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2


"Le présent courriel peut contenir des renseignements confidentiels et ne s'adresse qu'au destinataire dont le nom apparaît ci-dessus. Si ce courriel vous est parvenu par mégarde, veuillez le supprimer et nous en aviser aussitôt."