M
Matthew Braid
Hi all,
I'm using MIME::Tools and all its sundry packages to do some basic mail
manipulation (a little bit unbasic enough to not make MIME::Lite an option).
One part of my code requires attaching a new part onto an existing
message, and while the attach method is simple enough, I have to jump
though hoops when my data is stored in a file and I only have the
filehandle, not the file name.
At the moment, since the data could be quite large, I'm using
File::Temp::tempfile to create a temp file (requesting both a filehandle
and a name), copy the contents from the data filehandle into the
tempfile and then pass the tempfile's name to attach(). This is kind of
irksome because I know the function that returns the data filehandle
(which I can't change at the moment and would be a horrible hack if I
did) has already used File::Temp::tempfile to store the data in the
first place.
So at the moment I've got something like:
# -- START CODE --
my $datah = get_data(...); # The function that returns the data handle
# Its a library function so altering its
# return value would have numerous knock-on
# effects
my $mime = MIME::Entity->build(Data => 'Test',
From => '(e-mail address removed)',
To => '(e-mail address removed)',
Subject => 'This is a test');
{
# Urk
my ($tfh, $tempfile) = File::Temp::tempfile(UNLINK => 1);
while (defined(my $line = <$datah>)) {
print $tfh, $line;
}
$mime->attach(Path => $tempfile,
Type => 'application/octet-stream',
Encoding => 'base64');
}
# -- END CODE --
Being able to do something like:
$mime->attach(FH => $datah,
Type => 'application/octet-stream',
Encoding => 'base64');
would be infinitely preferable.
Is there any hidden way to do this, or can someone give me some tips as
to how to add this functionality to MIME::Entity?
MB
I'm using MIME::Tools and all its sundry packages to do some basic mail
manipulation (a little bit unbasic enough to not make MIME::Lite an option).
One part of my code requires attaching a new part onto an existing
message, and while the attach method is simple enough, I have to jump
though hoops when my data is stored in a file and I only have the
filehandle, not the file name.
At the moment, since the data could be quite large, I'm using
File::Temp::tempfile to create a temp file (requesting both a filehandle
and a name), copy the contents from the data filehandle into the
tempfile and then pass the tempfile's name to attach(). This is kind of
irksome because I know the function that returns the data filehandle
(which I can't change at the moment and would be a horrible hack if I
did) has already used File::Temp::tempfile to store the data in the
first place.
So at the moment I've got something like:
# -- START CODE --
my $datah = get_data(...); # The function that returns the data handle
# Its a library function so altering its
# return value would have numerous knock-on
# effects
my $mime = MIME::Entity->build(Data => 'Test',
From => '(e-mail address removed)',
To => '(e-mail address removed)',
Subject => 'This is a test');
{
# Urk
my ($tfh, $tempfile) = File::Temp::tempfile(UNLINK => 1);
while (defined(my $line = <$datah>)) {
print $tfh, $line;
}
$mime->attach(Path => $tempfile,
Type => 'application/octet-stream',
Encoding => 'base64');
}
# -- END CODE --
Being able to do something like:
$mime->attach(FH => $datah,
Type => 'application/octet-stream',
Encoding => 'base64');
would be infinitely preferable.
Is there any hidden way to do this, or can someone give me some tips as
to how to add this functionality to MIME::Entity?
MB