fdezmichael1
Technical User
Hi... i have this code....
#!/usr/bin/perl -w
use Mail::Internet;
require Mail::Address;
use Mail::Header;
use File::Find;
my $dir = "/var/spool/cyrus/mail/domain/r/domain.tld";
$file en process_an_email
find(\&find_emails => $dir);
sub find_emails {
return unless /\A[0-9]\.\z/;
return unless -f $File::Find::name;
process_an_email($File::Find::name);
return;
# print $File::Find::name, "\n";
}
$fecha =`date +%F--%k:%M`;
sub process_an_email {
my ($file) = @_;
open(FILE, $file);
$mi_obj = new Mail::Internet(\*FILE);
close(FILE);
$mi_obj->add("Procesado-por-script", "Si");
#$mi_obj->add("Fecha-de-Procesamiento", \$fecha);
$mi_obj->head->replace("Subject", "Tengo hambre.....");
@cuerpo = ("\nEsta es una prueba... reemplazando el cuerpo\n");
$mi_obj->body( \@cuerpo);
open(STDOUT, '>', "$file\.new");
$mi_obj->print_header(\*STDOUT);
$mi_obj->print_body(\*STDOUT);
chown(104, 8, "$file\.new");
}
Everything is working as I need, but now i need to add other header with the date... an that is in the variable $fecha, but every time i execute the script in the header:
Fecha-de-Procesamiento: i Got:
Fecha-de-Procesamiento: SCALAR(0x88deda8)
So... How can i show the date in the format that i need???
And other question is Why everything that I print is not going to STDOUT... because i am redirecting to a variable $file?, is there a way to redirect the STDOUT only in the sub process_an_email...? and in the rest it keep working as usual?
Thanks... a lot
Michael.-
#!/usr/bin/perl -w
use Mail::Internet;
require Mail::Address;
use Mail::Header;
use File::Find;
my $dir = "/var/spool/cyrus/mail/domain/r/domain.tld";
$file en process_an_email
find(\&find_emails => $dir);
sub find_emails {
return unless /\A[0-9]\.\z/;
return unless -f $File::Find::name;
process_an_email($File::Find::name);
return;
# print $File::Find::name, "\n";
}
$fecha =`date +%F--%k:%M`;
sub process_an_email {
my ($file) = @_;
open(FILE, $file);
$mi_obj = new Mail::Internet(\*FILE);
close(FILE);
$mi_obj->add("Procesado-por-script", "Si");
#$mi_obj->add("Fecha-de-Procesamiento", \$fecha);
$mi_obj->head->replace("Subject", "Tengo hambre.....");
@cuerpo = ("\nEsta es una prueba... reemplazando el cuerpo\n");
$mi_obj->body( \@cuerpo);
open(STDOUT, '>', "$file\.new");
$mi_obj->print_header(\*STDOUT);
$mi_obj->print_body(\*STDOUT);
chown(104, 8, "$file\.new");
}
Everything is working as I need, but now i need to add other header with the date... an that is in the variable $fecha, but every time i execute the script in the header:
Fecha-de-Procesamiento: i Got:
Fecha-de-Procesamiento: SCALAR(0x88deda8)
So... How can i show the date in the format that i need???
And other question is Why everything that I print is not going to STDOUT... because i am redirecting to a variable $file?, is there a way to redirect the STDOUT only in the sub process_an_email...? and in the rest it keep working as usual?
Thanks... a lot
Michael.-