[opencms-dev] serious bug in commons-email-1.0-mod.jar (class HtmlEmail)
Florian Heinisch
florian.heinisch at 3kraft.com
Mon Apr 28 13:04:59 CEST 2008
Dear OpenCms-Developers,
first of all I would like to thank you for your great work.
I am posting the first time to this dev list. Prior to writing this
post, I searched through the mail list archive and could not find any
related issues. If I did miss something by searching the mail list
archive and consequently post some redundant stuff here, please
forbear with me :)
I am using OpenCms 7.0.3 with the OAMP Newsletter module 1.0.
Using the Newsletter module, I was sending newsletters in HTML format
and realised that the larger the mailing list, the larger (in terms of
file size) the mails generated by the Newsletter module got.
After some testing, I saw that for every subscriber in the mailing
list the plaintext bodypart of the mail was attached once more. This
is, the first subscriber gets the only "correct" mail: one bodypart
containing the HTML mail and one bodypart containing the plaintext
mail. The second subscriber gets the one bodypart containing the HTML
mail and TWO (!!) bodyparts each containing the plaintext mail, the
third subscriber gets the mail containing one bodypart containin the
HTML mail and THREE bodyparts each containing the plaintext mail and
so on and so on.
So the 1000th subscriper gets the mail containing one bodypart with
the HTML mail and 1000 bodyparts each containing the plaintext mail.
As you can imagine, the mails are getting way to big.
Consequently, I had a closer look at the source code and I was quite
puzzled what I detected. I saw that you are using a patched version of
the Apache Commons Email 1.0 library. IMHO, it seems as a bad design
decision patching standard third party libraries rather than using
those libraries with an adapter or whatsoever.
After decompiling the patched commons email code (I could not find any
source code for this library) I found the bug in the class
org.apache.commons.mail.HtmlEmail in the method send():
By calling
MimeMultipart container = getContainer();
you get a reference to the existing MimeMulitpart object and you do
not create a new one (I think you should use createMimeMultipart()
but this method is not implemented in your library). Consequently,
with the following code you are adding a new bodyport with the
plaintext mail for every subscriber, although the bodypart with
plaintext mail already exists in the MimeMultipart object:
if(msgHtml == null)
{
msgText = getPrimaryBodyPart();
} else
{
msgText = new MimeBodyPart();
container.addBodyPart(msgText);
}
Did anyone of you already encounter this issue?
I think it would be a good idea to replace commons-email-1.0-mod.jar
with the standard commons email library. If you need any help to do
so, I would like to offer you my help to refactor the OpenCms code
that makes use of the commons-email-1.0-mod.jar.
Many regards,
Florian
More information about the opencms-dev
mailing list