On 8/5/11 12:05 AM, David F. Skoll wrote:
On Thu, 04 Aug 2011 21:03:45 +0200
"Rolf E. Sonneveld"<[email protected]> wrote:
OK, I finally managed to get the contents of the bodypart correct by
using the as_string method for $entity->bodyhandle during 'filter'
phase. Is that the correct/best way to do it, or should I have used
another approach?
You are over-thinking it. As far as I know:
$parent_entity->add_part($sub_entity);
should work, where both $parent_entity and $sub_entity are MIME::Entity
instance.
I tried this and it works, although both the content-type and the
content-transfer-encoding of the bodypart got mangled: an audio/wav with
content-transfer-encoding (CTE) 'base64' became text/plain with CTE
'binary'.
So, I got this behaviour with the following setup:
During filter phase, for that particular bodypart:
$originalbody = $entity->body;
$head = $entity->head;
$encoding = $head->mime_encoding;
Then during filter_end:
$parent_entity = MIME::Entity->build (<parameters for primary html
bodypart>);
$parent_entity->make_multipart;
$sub_entity = MIME::Entity->build(Data => $originalbody);
$parent_entity->add_part($sub_entity);
Next, I tried to fix that using $entity->head->mime_attr, using the
original bodypart type and original encoding (base64):
$sub_entity = MIME::Entity->build(Data => $originalbody);
$sub_entity->head->mime_attr("content-transfer-encoding",$encoding);
$parent_entity->add_part($sub_entity);
After this 'fix' the CTE at the receiving side is OK (base64), but the
contents of the bodypart are (again) base64 encoded (i.e. the original
base64 bodypart is encoded again with base64, leaving a 'double-encoded'
part).
So no matter whether I give the CTE during the MIME::Entity->build, or
whether I add it later on, as soon as I use a CTE of base64 the
base-64-encoded-bodypart is encoded again with base64. And if I don't
use an encoding, I get text/plain with a CTE of 'binary'.
So the only solution which seems to work for me is to first decode the
bodypart (with the bodyhandle->as_string approach) and then have it
encoded again (during the build or thereafter during the fixup of the
encoding).
If I'm over-thinking it, some working sample code (without the
bodyhandle->as_string 'hack') is very much appreciated.
Thanks,
/rolf
_______________________________________________
NOTE: If there is a disclaimer or other legal boilerplate in the above
message, it is NULL AND VOID. You may ignore it.
Visit http://www.mimedefang.org and http://www.roaringpenguin.com
MIMEDefang mailing list [email protected]
http://lists.roaringpenguin.com/mailman/listinfo/mimedefang