in reply to Re: New Lines are not printing after certain messages
in thread New Lines are not printing after certain messages

we are using Outlook 2003.
sub mail_admin { local($sub,$msg) = @_; $curAdmins = "/opt/local/etc/cur_admins"; @cur_admin_lines = `cat $curAdmins`; chomp(@cur_admin_lines); foreach $cur_admin_line (@cur_admin_lines) { ($id,$name,$group,$OncallFlag,$address) = split(/:/, $cur_admin_li +ne); $cur_admin_addresses .= " $address"; } my $cmd = "echo \"$msg\" | mail -s \"$sub\" $cur_admin_addresses"; system("$cmd"); my($rc) = $? / 256; if ($rc != 0) { &pager("Can't send mail_admin message $msg - rc = $rc", P); } }

Replies are listed 'Best First'.
Re^3: New Lines are not printing after certain messages
by ikegami (Patriarch) on Mar 31, 2008 at 21:57 UTC
    • "$cmd"
      needless creates a copy of $cmd. Just use
      $cmd

    • local?!
      local($sub,$msg) = @_;
      should be
      my($sub,$msg) = @_;

    • What's with launching another process to read a file?
      @cur_admin_lines = `cat $curAdmins`;
      should be

      my @cur_admin_lines = do { open(my $fh, '<', $curAdmins) or die("Unable to read list of admins ($curAdmins): $!\n"); <$fh> };
    • echo? print!

      my $cmd = "echo \"$msg\" | mail ..."; system("$cmd");

      should be

      my $cmd = "mail ..."; open(my $fh, '|-', $cmd) or ...; print $fh $msg; close($fh);
    • And it's already been pointed out that $msg and $sub aren't properly converted from string to shell argument literals. Using MIME::Lite would avoid that problem.

Re^3: New Lines are not printing after certain messages
by wojtyk (Friar) on Mar 31, 2008 at 20:27 UTC
    How is that working at all?
    Since you're building a scalar ($cmd) that is getting interpolated before getting called by system, the message and subject are not literals (they're interpolated as well)
    What happens when $msg is this:
    $msg = '"|touch file_i_shouldnt_be_allowed_to_create|"';

    I imagine it's at least part of the source of your troubles (and highly dangerous from a security standpoint).