On 8/23/06, Arien <[EMAIL PROTECTED]> wrote:
I'm running into a related issue with a plugin that strips attachments
from email (using MIME::Parser) and makes them available for download.
The relevant snippet of the source:
my $email = $parser->parse_open($transaction->body_filename);
$email = strip_attachments($email, $root_url);
open FILE, '>', $transaction->body_filename
or die "Couldn't open temporary message body: $!\n";
$email->print(\*FILE)
or die "Couldn't write temporary message body: $!\n";
close FILE
or die "Couldn't close temporary message body: $!\n";
As it is, I would have to update $email->head with the headers
according to $transaction->header before stripping the attachments,
and update $transaction->header with the new headers (i.e. those in
$email->head after stripping).
Besides this, I would have to write the old headers followed by the
new body to disk, so Qpsmtpd::Transaction->{_header_size} (and
_body_start) stays in sync.
Doing what I described above leads to this working code:
my $email = $parser->parse_open($transaction->body_filename);
# stash away headers as on found disk
my $prev_head = $email->head->as_string;
# sync headers with transaction's (possibly updated) headers ...
$email->head->header([ split /^/, $transaction->header->as_string ]);
$email = strip_attachments($email, $root_url);
# ... and sync the other way to maintain the illusion
$transaction->header->header([ split /^/, $email->head->as_string ]);
# Write original headers and updated body
open FILE, '>', $transaction->body_filename
or die "Couldn't open message body: $!\n";
print FILE "$prev_head\n" and $email->print_body(\*FILE)
or die "Couldn't write message body: $!\n";
close FILE
or die "Couldn't close message body: $!\n";
Still, I keep wondering if there isn't a better way to do this....
Arien