users@javamail.java.net

Re: multiple 'Re: ' prefixed in replies

From: Bill Shannon <bill.shannon_at_oracle.com>
Date: Mon, 01 Jul 2013 11:07:35 -0700

In a perfect world, everyone would understand and use utf-8.

In the real world, you'll sometimes find mailers that only understand
their local charset. So, you might get a message with a Subject field
with some words encoded using (e.g.) a Japanese charset. When you call
the getSubject method, JavaMail (using the JDK) will convert that to
Unicode characters. If you then call the setSubject method with the modified
subject and tell it to use utf-8 to encode it, the original mailer might not
be able to decode it.

Yes, hopefully that's a rare situation these days.

An even more rare case is when the sender uses a non-standard charset that
the JDK doesn't know how to decode, so the getSubject call will fail.

It's for all these reasons that JavaMail chose to manipulate the reply
Subject header without decoding the original Subject header.

xoot123_at_yahoo.it wrote on 07/01/13 00:42:
> I omitted a detail, the application that adds multiple 'Re: ' is the same I'm
> working on, it was a test sending a message to my address with the same
> application and replying back multiple times.
>
> As the application just calls reply() on the IMAPMessage, I see the prefix is
> added each time. That's how I think it works, I'll however give a look at the
> code again to be sure nothing more is done on the message. And I'll try your
> workaround too.
>
> I'm not getting, though, your warning about always using utf-8: if I manipulate
> the message through JavaMail APIs, shouldn't it work with the set charset?
>
>
>
> Thanks
> M. R.
>
>
>
> --------------------------------------------------------------------------------
> *Da:* Bill Shannon <bs00011_at_gmail.com>
> *A:* xoot123_at_yahoo.it
> *Cc:* "users_at_javamail.java.net" <users_at_javamail.java.net>
> *Inviato:* Giovedì 27 Giugno 2013 19:31
> *Oggetto:* Re: multiple 'Re: ' prefixed in replies
>
> xoot123_at_yahoo.it <mailto:xoot123_at_yahoo.it> wrote on 06/27/2013 05:55 AM:
>> Hello,
>> when I receive an email whose subject has accented letters (i.e.
>> "ripròva") the first reply shows the subject "Re: ripròva", but the next
>> reply to the latter shows "Re: Re: ripròva", adding another prefix.
>> This is because in the actual email text the subject header is like
>> "Subject: =?UTF-8?Q?Re:_ripr=C3=B2va?=", so I guess that the existing "Re:
>> " isn't detected by Javamail and another one is prefixed.
>>
>> When the subject is shown in the application it looks fine, so the utf-8
>> encoding is properly decoded.
>>
>> Is this something that can be fixed with a JavaMail parameter? Should I
>> manipulate somehow the subject before invoking reply()?
> The code currently has this comment:
>
> /*
> * Have to manipulate the raw Subject header so that we don't lose
> * any encoding information. This is safe because "Re:" isn't
> * internationalized and (generally) isn't encoded. If the entire
> * Subject header is encoded, prefixing it with "Re: " still leaves
> * a valid and correct encoded header.
> */
>
> There's really no need to encode the word "Re:", so applications that do so
> are just being lazy. I suppose JavaMail could decode the header first, and
> then prepend an unencoded "Re:" to the encoded header if necessary.
>
> As a workaround you can use getSubject() on the reply message and strip off
> multiple instances of "Re:" and use setSubject() on the result. That will
> work fine as long as all the encoding information is correct in the original
> message and you're willing to always use utf-8 for the reply message.
>
>
>