Re: How attach files and send mails on perl????
[email protected] ("John W. Krahn")
| Newsgroups | perl.beginners |
|---|---|
| Message-ID | <[email protected]> |
Armin Garcia wrote:
> Hi !!!!
Hello,
> Well i try to attach a file, but i dont know what function or method i need
> to use, here is my code, i hope anybody can help me .... thanks
> (im only want to attach files, thanlks )
>
>
> #!/usr/bin/perl
use warnings;
use strict;
> use Mail::Internet;
> use Mail::Box::Manager;
> use Email::Folder;
>
> $folder_file = "/home/agarcia/HoneyClient/Mbox-Folder/posible_spam";
> $salida =
> "/usr/local/Honeyclient/HoneyClient3/ScriptHoney/capture-server-2.1.0-300/Urls-Malware/filtrar.txt";
> $UrlsFiltrar =
> "/usr/local/Honeyclient/HoneyClient3/ScriptHoney/capture-server-2.1.0-300/Urls-Malware/Urls-Malware.txt";
>
> # Abrimos el buz–™n.
> my $mgr = Mail::Box::Manager->new;
> $i=0;
>
> $folder = Email::Folder->new($folder_file);
> @urls = ();
> $dir;
Why do you have a scalar variable in void context?
> %Urls=();
> if ( -e $salida ){
> `rm -rf $salida`;
perldoc -q "What.s wrong with using backticks in a void context?"
> }
>
> sub Parser {
>
> open (F,"< $salida") || die "No se pudo abrir el archivo";
You should include the $! variable in the error message so you know
*why* open failed.
> @urls=<F>;
> $i=0;
> open (G, "> $UrlsFiltrar") || die "No se pudo crear";
You should include the $! variable in the error message so you know
*why* open failed.
> foreach (@urls){
> @aux=split(" ",@urls);
That is the same as:
@aux = scalar @urls;
The split() is superfluous because @urls in scalar context does not
contain any whitespace.
But you are not using @aux anywhere so why is that line there?
> $URLS{$urls[$i]}++;
> $i++;
You are looping over the array @urls so those two lines should be:
$URLS{$_}++;
> }
> foreach $var(keys %URLS){
> print G "$var";
> }
> close(F);
> close(G);
> }
>
> sub EnviarCorreo {
> $repfrom = shift(@_);
> $arch = shift (@_);
You are not using the variables $repfrom and $arch anywhere after this?
> $correos="agarcia\@server1.com.mx";
>
> open(DATOS,$UrlsFiltrar);
> @body = <DATOS>;
> close(DATOS);
>
> open(MAIL, "| /usr/sbin/sendmail $correos");
You should *always* verify that the pipe opened correctly, like you have
obviously verified file opens elsewhere in your program.
> print MAIL "From: agarcia\@localhost\n";
> print MAIL "To: agarcia\@server1.com.mx\n";
> print MAIL "Subject: test !!!!!\n\n";
> print MAIL @body;
> close(MAIL);
You should *always* verify that the pipe closed correctly.
> }
>
> for ($folder->messages) {
> for ( $_->body ) {
> if ( $_ =~ /http:/ ) {
> @urls = /(((ftp|http|https):\/\/|www\.)([\w*\-?\w*\.]+)*)/g;
Your character class [\w*\-?\w*\.] could be written more simply as
[\w*.?-]. Is the '*' character valid in a URL? Why is it
'(ftp|http|https):\/\/' *OR* 'www\.', you *can* have both at the same time.
> }
> }
>
> open (F," >> $salida") || die "No se puede crear el archivo ...";
You should include the $! variable in the error message so you know
*why* open failed.
> foreach my $url (@urls) {
> print F "$url\n";
> }
> close(F);
> }
John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall