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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

trouble emailing files with commas from an array

Status
Not open for further replies.

nix45

MIS
Nov 21, 2002
478
US
I have a script that looks at the files in a directory and displays them in a web page with check boxes next to each one. When you check off the files that you want, it emails them to you. The script works except when there are commas in the filename. Each filename is passed into an array, and then a foreach loop emails each one out using the Mail::Sender module. Here's a sample of the script...

Code:
use CGI qw(:standard);
use Mail::Sender;

@emails = ();			# the files that the user wants emailed to them
@list = param();		            # holds the parameters passed to the script
$date = param('date');		# either the current month (SomeFolder) or last month (SomeFolder2)
$emailto = param('emailto');	# email to this address
$counter = 0;			# temporary counter

$email = 'helpdesk@foo.us';

foreach $selection (@list) {
   if ($selection != /\d+/) {
      $file = param($selection);
      push @emails, $file;
   }
}

print header('Email Files');
print start_html;

if ($date eq 'current') { chdir 'E:\SomeFolder'; } else { chdir 'E:\SomeFolder2'; }

foreach (@emails) {

  if ($emailto eq undef) {   
    if ($_ =~ /.+@.+\..+_(.+@.+\..+?)_.+_/) {
      $emailto = $1;
    }
  }


  $sender = new Mail::Sender
  {smtp => '192.0.1.2', from => "Helpdesk@foo.us"};
  $sender->MailFile({to => "$emailto",
  subject => 'Files',
  msg => "These are the files you requested.",
  file => "$_"});

  print "<p>$_ was released to $emailto</p>";
  
}

print end_html;


Thanks,
Chris
 
I'd probably have a look at URI::Escape. If there's a comma being passed to your script from the form, it's not being passed as a comma, it's being passed as its ascii equiv.

--
Andy
&quot;Historically speaking, the presence of wheels in Unix has never precluded their reinvention.&quot;
Larry Wall
 
If I print each file that I want to email, it does show as a comma like it should.

I'm a little confused over URI::Escape...

Code:
uri_escape($string, [$unsafe])

Replaces each unsafe character in the $string with the corresponding escape sequence and returns the result.

If I replace the comma with another character, I won't be able to email the file out (not that I can now or anything though:) )because the file name would be changed. Am I missing something here? I probably am.

Thanks,
Chris
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top