dcsimg
What's the best way to create a modified copy of a MimeMessage object?
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Gary_Taylor
Posted On:   Monday, October 7, 2002 09:09 AM

I've got a MimeMessage object, and I need to create a modified copy of it - potentially stripping attachments over a certain size, removing any recognised header/footer blocks from text/plain parts, converting text/html to text/plain etc. Now currently, I'm traversing the original MimeMessage and dynamically building up a new MimeMessage object based on the original after applying any of the "modification" rules we have. The problem we've come up against is that when the original MimeMessage contains a large attachment part then when we write out the copied MimeMessage object it takes ages - I've tracked it down to the DataHandler for that part, but I've yet to find out what the problem is (I'm doing the newMsg.setDataHandle   More>>


I've got a MimeMessage object, and I need to create a modified copy of it - potentially stripping attachments over a certain size, removing any recognised header/footer blocks from text/plain parts, converting text/html to text/plain etc.



Now currently, I'm traversing the original MimeMessage and dynamically building up a new MimeMessage object based on the original after applying any of the "modification" rules we have. The problem we've come up against is that when the original MimeMessage contains a large attachment part then when we write out the copied MimeMessage object it takes ages - I've tracked it down to the DataHandler for that part, but I've yet to find out what the problem is (I'm doing the newMsg.setDataHandler(origMsg.getDataHandler()) thing)



I've just been browsing the FAQ, and it reminded me that you can easily clone a MimeMessage object. So - do you think it would be better to clone the original MimeMessage first, and then apply the modifications retrospectively to the copy, rather than dynamically build up the copy ?

   <<Less

Re: What's the best way to create a modified copy of a MimeMessage object?

Posted By:   Christopher_Koenigsberg  
Posted On:   Monday, October 7, 2002 09:57 AM

The usual questions about a "clone" operation are whether it is "deep" or "shallow", and if it is "deep", whether it is "lazy" or not...



Try it and let us know how it works out. If the clone is "shallow" and not "deep", then it might just be making a new quick copy of the top level MimeMessage object, e.g. not actually copying any of the body parts (attachments), so the cloning might be quick, and removing the large attachment part from the clone might be quick too (as long as the ref remains, to the large attachment part, in the original copy, which I assume you want to keep intact?). The danger here would be the aliasing of the 2 ref's to the body part objects, if you changed the content of one of them (in the clone) and hence changed it in the original too.



If the clone is "deep", but not "lazy", then it might take just as long, for the act of cloning to copy the large attachment part, as if you do the copy explicitly yourself (unless it can bypass the content handler somehow? maybe if the attachment part itself has a quick "clone" of its own).



Or the clone could be "deep but lazy", and not actually copy the large attachment part object if you don't open it, but to still let you remove it quickly (just the ref to it) from the cloned copy (and still only affect the clone and not the original).

About | Sitemap | Contact