Armin Garcia wrote:
> Hi !!!!
> 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 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;
> %Urls=();
> if ( -e $salida ){
> `rm -rf $salida`;
> }
> 
> sub Parser {
> 
> open (F,"< $salida") || die "No se pudo abrir el archivo";
>         @urls=<F>;
> $i=0;
> open (G, "> $UrlsFiltrar") || die "No se pudo crear";
> foreach (@urls){
> @aux=split(" ",@urls);
> $URLS{$urls[$i]}++;
>                 $i++;
>      }
>         foreach $var(keys %URLS){
>             print G "$var";
>         }
>         close(F);
>         close(G);
> }
> 
> sub EnviarCorreo {
> $repfrom = shift(@_);
> $arch = shift (@_);
> $correos="[EMAIL PROTECTED]";
> 
> open(DATOS,$UrlsFiltrar);
> @body = <DATOS>;
> close(DATOS);
> 
> open(MAIL, "| /usr/sbin/sendmail $correos");
> print MAIL "From: [EMAIL PROTECTED]";
> print MAIL "To: [EMAIL PROTECTED]";
> print MAIL "Subject: test !!!!!\n\n";
> print MAIL @body;
> close(MAIL);
> }
> 
> for ($folder->messages) {
>  for ( $_->body ) {
> if ( $_ =~ /http:/ ) {
> @urls = /(((ftp|http|https):\/\/|www\.)([\w*\-?\w*\.]+)*)/g;
> }
> }
> 
> open (F," >> $salida") || die "No se puede crear el archivo ...";
> foreach my $url (@urls) {
> print F "$url\n";
> }
>  close(F);
> }
> 
> Parser;
> EnviarCorreo($salida);

I'm afraid I can't understand your code. Others who are familiar with the
modules you are using may fare better, but I'm surprised that you need three 
modules

  use Mail::Internet;
  use Mail::Box::Manager;
  use Email::Folder;

to handle what seems to be a fairly simple task.

First of all, please start with

  use strict;
  use warnings;

at the start of the program, and declare all variables as necessary. It would
also help if you indented your code so that the block structure is apparent.

It is best practice to use scalar variables for file handles, to use the
three-parameter form of open, and provide the value of the error condition $! in
your die string, so that

  open (G, "> $UrlsFiltrar") || die "No se pudo crear";

becomes

  open my $g, '>', $UrlsFiltrar or die "No se pudo crear: $!";

also

  open(DATOS,$UrlsFiltrar);
  @body = <DATOS>;
  close(DATOS);

is neater as

  my @body = do {
    open my $datos, '<', $UrlsFiltrar or die $!;
    <$datos>;
  };

Once you have made your code more visible I'm sure there are many others who
will help you.

HTH,

Rob

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to