in reply to New Lines are not printing after certain messages

What email client are you using, and what module or mechanism does &mail_admin use to send mail?

Replies are listed 'Best First'.
Re^2: New Lines are not printing after certain messages
by tbest4475 (Initiate) on Mar 31, 2008 at 19:44 UTC
    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); } }
      • "$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.

      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).