Regarding this script which was provided by Rob M at
See my response beneath the second dashed line below:
-----------------------------------------------------------------------------------------------------------
#!/usr/bin/perl -w
use strict;
use MIME:arser;
my $logfile='/home/directory/attaches.log';
my $attachdir='/home/directory';
my $parser=new MIME:arser;
$parser->ignore_errors(1);
$parser->extract_uuencode(1);
$parser->tmp_recycling(0);
$parser->output_to_core(1);
my $entity=$parser->parse(*STDIN);
my $from=$entity->head->get('From');
my $subject=$entity->head->get('Subject');
my @parts=$entity->parts;
my $aname='attachment001';
while(my $part = shift(@parts)) {
if($part->parts) {
push @parts,$part->parts; # Nested multi-part
next;
}
my $type=$part->head->mime_type || $part->head->effective_type;
if($type !~ /^(text|message)/i) { # Not a text, save it
my $filename=$part->head->recommended_filename || $aname;
$aname++;
my $io=$part->open("r"
my $uniq=time().'-'.$$;
$filename =~ s/[;<>*|`&\$!#()[]{}:'"\n]//g;
open(F,">> $attachdir/$uniq-$filename"
my $buf;
while($io->read($buf,1024)) {
print F $buf;
}
close(F);
$io->close;
open(LOG,">> $logfile"
print LOG localtime()." From: $from\tSubject: $subject\tFile: $uniq-$filename\n";
close(LOG);
}
}
exit;
-----------------------------------------------------------------------------------------------------------
Rob M (and anyone else that can help)
I tested your above script and it is one GREAT script!
Thank you!
I'm new to all this, but am trying to customize your script
so that I can use it for the specific purpose I have in mind.
I have an email-to-cgi script (see it below) that automatically
sends out a preformatted email and attachment in response
to a particular email address sent to me.
I was looking for a script that extracts attachments and deposits
them in a directory on my server when I found your script, which
I just love because it not only logs the incoming emails, but also
generates different file names for each attachment by appending
the existing filename, which would be great for a future project.
I'm not sure how the "10 digit dash five digit dash" numbering
is determined (doesn't seem to correspond with time and date
or any other info I can recognize), but I would really like to
know : )
My question is:
1) If I wanted the script to rename incoming email attachments
(there would only be one attachment per email from a unified
messaging service) with the same name so that the new file
attachment would simply re-write over the existing file with the
same name already in the server directory it's being extracted to,
how would the script look then, and is there a way to either...
1a) incorporate the script below so that it will "also" execute,
and send out the file that was just extracted and renamed to
its directory, or alternatively...
1b) If 1a above can't be done, can a few few lines of code be
inserted into the script answer for question 1 above so that
the script will simply generate any kind of email, so that I can
use that email to execute the script below (assuming the script
below can't be incorporated into the script answer for question
1 above).
Here's the email-to-cgi script I'm using which automatically
sends out a preformatted email
--------------------------------------------------------------------------
#!/usr/bin/perl
use strict;
use MIME::Lite;
my @email=<STDIN>;
my $msg = MIME::Lite->new(
To => 'to@getaloan.net',
From => '1877LoanOfficer@getaloan.net',
Subject => 'Extension 3 Subject Line',
Type => 'multipart/mixed',
);
$msg->attach(Type =>'TEXT',
Data =>"Here's the mp3 file you wanted"
);
$msg->attach(
Type => 'audio/x-mpeg',
Path => '/usr/home/getaloan.net/htdocs/voicemail.mp3',
);
$msg->send;
--------------------------------------------------------------------------
Thanks Rob and/or, et al
See my response beneath the second dashed line below:
-----------------------------------------------------------------------------------------------------------
#!/usr/bin/perl -w
use strict;
use MIME:arser;
my $logfile='/home/directory/attaches.log';
my $attachdir='/home/directory';
my $parser=new MIME:arser;
$parser->ignore_errors(1);
$parser->extract_uuencode(1);
$parser->tmp_recycling(0);
$parser->output_to_core(1);
my $entity=$parser->parse(*STDIN);
my $from=$entity->head->get('From');
my $subject=$entity->head->get('Subject');
my @parts=$entity->parts;
my $aname='attachment001';
while(my $part = shift(@parts)) {
if($part->parts) {
push @parts,$part->parts; # Nested multi-part
next;
}
my $type=$part->head->mime_type || $part->head->effective_type;
if($type !~ /^(text|message)/i) { # Not a text, save it
my $filename=$part->head->recommended_filename || $aname;
$aname++;
my $io=$part->open("r"
my $uniq=time().'-'.$$;
$filename =~ s/[;<>*|`&\$!#()[]{}:'"\n]//g;
open(F,">> $attachdir/$uniq-$filename"
my $buf;
while($io->read($buf,1024)) {
print F $buf;
}
close(F);
$io->close;
open(LOG,">> $logfile"
print LOG localtime()." From: $from\tSubject: $subject\tFile: $uniq-$filename\n";
close(LOG);
}
}
exit;
-----------------------------------------------------------------------------------------------------------
Rob M (and anyone else that can help)
I tested your above script and it is one GREAT script!
Thank you!
I'm new to all this, but am trying to customize your script
so that I can use it for the specific purpose I have in mind.
I have an email-to-cgi script (see it below) that automatically
sends out a preformatted email and attachment in response
to a particular email address sent to me.
I was looking for a script that extracts attachments and deposits
them in a directory on my server when I found your script, which
I just love because it not only logs the incoming emails, but also
generates different file names for each attachment by appending
the existing filename, which would be great for a future project.
I'm not sure how the "10 digit dash five digit dash" numbering
is determined (doesn't seem to correspond with time and date
or any other info I can recognize), but I would really like to
know : )
My question is:
1) If I wanted the script to rename incoming email attachments
(there would only be one attachment per email from a unified
messaging service) with the same name so that the new file
attachment would simply re-write over the existing file with the
same name already in the server directory it's being extracted to,
how would the script look then, and is there a way to either...
1a) incorporate the script below so that it will "also" execute,
and send out the file that was just extracted and renamed to
its directory, or alternatively...
1b) If 1a above can't be done, can a few few lines of code be
inserted into the script answer for question 1 above so that
the script will simply generate any kind of email, so that I can
use that email to execute the script below (assuming the script
below can't be incorporated into the script answer for question
1 above).
Here's the email-to-cgi script I'm using which automatically
sends out a preformatted email
--------------------------------------------------------------------------
#!/usr/bin/perl
use strict;
use MIME::Lite;
my @email=<STDIN>;
my $msg = MIME::Lite->new(
To => 'to@getaloan.net',
From => '1877LoanOfficer@getaloan.net',
Subject => 'Extension 3 Subject Line',
Type => 'multipart/mixed',
);
$msg->attach(Type =>'TEXT',
Data =>"Here's the mp3 file you wanted"
);
$msg->attach(
Type => 'audio/x-mpeg',
Path => '/usr/home/getaloan.net/htdocs/voicemail.mp3',
);
$msg->send;
--------------------------------------------------------------------------
Thanks Rob and/or, et al