Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MIME::Parser

Status
Not open for further replies.

gordonisnz

Programmer
Aug 10, 2003
14
0
0
NZ
Hi there

Im using MIME::parser

& it IS working.. - Saving the attachments onto my server etc..

HOWEVER

It is saving the attachments with a 0 / ZERO / NIL file-size...

Heres the snippets of parser code (excluding any print statements - not relatring to theparsing of messages)



use MIME::parser;

my $parser = new MIME::parser;
$parser->ignore_errors(1);
$parser->extract_uuencode(1);


$parser->output_under("$fle");

# $fle is the directory to save the text/files to

$entity = $parser->parse_data($content);
my $results = $parser->results;

(I parse the $results, to locate the files - later on.. )




Hmm - thats it - No other $parser codes...

Am I missing anything ??

Has someone got a COMPLETE code of what im trying to do ?
(IE if I send a 15KB file to the server by email, I expect a 15KB file to be saved on the server & re-sent to wherever it is needed)

It SAVES the file as 0/nil/zero bytes - & re-sends the file - (as saved) - as zero/0 bytes - Useless to the recipient :-(

Can anyone help.

G
 
I've started reading the MIME::Tools documentation <sigh> there's quite a lot of it isn't there.....

Anyway -- it mentions that there are examples in &quot;examples directory of the MIME-tools distribution.&quot;

Have you checked these out?

Meantime - I'll carry on reading.


Mike

Want to get great answers to your Tek-Tips questions? Have a look at faq219-2884

It's like this; even samurai have teddy bears, and even teddy bears get drunk.
 
Where can they be - Online ?

Havnt used MIME::Tools - I guess its a bundle of all the MIME things ?

G
 
Do you have a directory named &quot;examples&quot; in your MIME directories?

And yes - MIME::Tools contains MIME::parser etc.

Just having a look at the examples you specified above.

Mike

Want to get great answers to your Tek-Tips questions? Have a look at faq219-2884

It's like this; even samurai have teddy bears, and even teddy bears get drunk.
 
what do youmean &quot;examples&quot; directrey ?

Im using the MIME - supplied by my ISP / Webhost

The directory name changes - depending on where the email is directed to, & the MIME creates a subdirectory of
msg_xxxxx_blah_blah/ & inserts the TXT / Attachment files there...

Ive got the FULL text, however any attachments are all ZERO bytes..

I'm posting the same problem on 3-4 message boards, & 1-2 email Perl discussion groups.

covering over 10,000 people - (if they all read my messages)

Im sure at LEAST one person has an answer ?

G

 
Gordon,

Please don't be impatient. I was trying to work through the problem with you as no-one else had picked it up.

If you download the MIME package from CPAN, as I did, you'll find that you have an examples directory in there.

One of the examples is the following script, which looks as if it might well help you.

#!/usr/bin/perl -w

=head1 NAME

mimedump - dump out the contents of a parsed MIME message


=head1 DESCRIPTION

Read a MIME stream from the stdin, and dump its contents to the stdout.


=head1 SYNOPSIS

mimedump < mime.msg


=head1 AUTHOR

Andreas Koenig suggested this, and wrote the original code.
Eryq perverted the hell out of it.

=cut

use MIME::parser;

#------------------------------
#
# dump_entity ENTITY, NAME
#
# Recursive routine for dumping an entity.
#
sub dump_entity {
my ($entity, $name) = @_;
defined($name) or $name = &quot;'anonymous'&quot;;
my $IO;

# Output the head:
print &quot;\n&quot;, '=' x 60, &quot;\n&quot;;
print &quot;Message $name: &quot;;
print &quot;\n&quot;, '=' x 60, &quot;\n\n&quot;;
print $entity->head->stringify;
print &quot;\n&quot;;

# Output the body:
my @parts = $entity->parts;
if (@parts) { # multipart...
my $i;
foreach $i (0 .. $#parts) { # dump each part...
dump_entity($parts[$i], (&quot;$name, part &quot;.(1+$i)));
}
}
else { # single part...

# Get MIME type, and display accordingly...
my ($type, $subtype) = split('/', $entity->head->mime_type);
my $body = $entity->bodyhandle;
if ($type =~ /^(text|message)$/) { # text: display it...
if ($IO = $body->open(&quot;r&quot;)) {
print $_ while (defined($_ = $IO->getline));
$IO->close;
}
else { # d'oh!
print &quot;$0: couldn't find/open '$name': $!&quot;;
}
}
else { # binary: just summarize it...
my $path = $body->path;
my $size = ($path ? (-s $path) : '???');
print &quot;>>> This is a non-text message, $size bytes long.\n&quot;;
print &quot;>>> It is stored in &quot;, ($path ? &quot;'$path'&quot; : 'core'),&quot;.\n\n&quot;;
}
}
1;
}

#------------------------------
#
# main
#
sub main {
print STDERR &quot;(reading from stdin)\n&quot; if (-t STDIN);

# Create a new MIME parser:
my $parser = new MIME::parser;

# Create and set the output directory:
(-d &quot;mimedump-tmp&quot;) or mkdir &quot;mimedump-tmp&quot;,0755 or die &quot;mkdir: $!&quot;;
(-w &quot;mimedump-tmp&quot;) or die &quot;can't write to directory&quot;;
$parser->output_dir(&quot;mimedump-tmp&quot;);

# Read the MIME message:
$entity = $parser->read(\*STDIN) or die &quot;couldn't parse MIME stream&quot;;

# Dump it out:
dump_entity($entity);
}
exit(&main ? 0 : -1);

#------------------------------
1;




Mike

Want to get great answers to your Tek-Tips questions? Have a look at faq219-2884

It's like this; even samurai have teddy bears, and even teddy bears get drunk.
 
EEEK - ive found HUNDREDS of files with the attachments

in an obscure location of my server :-(

with the FULL attachments (eg not 0 bytes)

I'll have to back-track with one of the scripts ive used in the last few days (14th August) - to find which one worked..

I wish I saw the directories earlier :-(

AAAARRRGGHHHH!!!!!!

G

 
OK

Ive done a quick test...

The files (attachments) are *ALL* a maximum of 3KB

The working script is below...

I'm off to bed now - But will work on it tomorow...
(I deleted the script (section) , & found my script didnt work at all - So i spent an hour or so trying to re-create a working code (so messages can pass through the system)

Anyways - Is there a command in MIME::parser that restricts the size to a certain ammount ?

eg - 3KB
- If so, Is there a perl command to over-ride / Increase the size


Ok _ i'll send this to my ISP/host too..

i'm off to bed - Goodnight, & thanks for the help..

G




use MIME::parser;
my $parser = new MIME::parser;

$fle = &quot;/## FLE is the destination directory / group - i want the file saved to...

print &quot;FROM - $from\n&quot;;
print &quot;LINE - $line\n&quot;;
print &quot;TO - $to\n&quot;;
print &quot;SUBJECT - $subject\n&quot;;

print &quot;FILE - $fle\n\n\n&quot;;

$parser->output_under(&quot;$fle&quot;);
$entity = $parser->parse_data($content);

## CONTENT is the full email (headers & all )

my $results = $parser->results;

use Data::Dumper; $Data::Dumper::Indent=1;

#my $entity = $parser->parse_data($msg);
$atemp = Data::Dumper->Dump([$results], [qw($results)]);


### Search data - Find filenames (includes text / message body)

@temp = split (/debug:/,$atemp);

foreach $linex (@temp){
chomp($linex);

$linex =~ s/\'/ /gi;
$linex =~ s/\,/ /gi;
$linex =~ s/\n/ /gi;
$linex =~ s/\s\s+/ /gi;
$linex =~ s/^\s//gi;
$linex =~ s/\s$//gi;
if ($linex =~ m/body to disk/i){

$g = length($linex);
$l=0;
while (substr($linex,$l,$g) =~ m/ /i){
$l++;
}

$as = substr($linex,$l,$g);

# As is the last 'word' on the line - the filename & position

#print &quot;abz '&quot;.substr($linex,$l,$g).&quot;'\n&quot;;
#print &quot;AS1 '$as'\n&quot;;
$as = substr($linex,$l,$g);
$as =~ s/^\s+//gi;
$as =~ s/\s+$//gi;
#print &quot;AS2 '$as'\n&quot;;

$files{$as}=1;

}
## $files now contain the location of the file & the name


#### FINISHED OFF HERE ################################

}



print &quot;\n\nCONTENT - \n$results\n$entity\n&quot;;

foreach $linex (@results){
print &quot;$linex\n&quot;;


print &quot;\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n&quot;;



print &quot;\n\n&quot;;



######### END OF TEST

}
 
Yay :) Progress....

Catch you later Gordon

Mike

Want to get great answers to your Tek-Tips questions? Have a look at faq219-2884

It's like this; even samurai have teddy bears, and even teddy bears get drunk.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top