Name

mail —

ATTRIBUTES

Attribute Pos. Req. Default Description
raw
extra
show
success
interpolate     0 interpolate input?
reparse     1 interpolate output?
hide     0 Hide the tag return value?

DESCRIPTION

BEHAVIOR

This tag does not appear to be affected by, or affect, the rest of Interchange.

EXAMPLES

No examples are available at this time. We do consider this a problem and will try to supply some.

NOTES

AVAILABILITY

mail is available in Interchange versions:

4.6.0-5.9.0 (git-head)

SOURCE

Interchange 5.9.0:

Source: code/SystemTag/mail.coretag
Lines: 15


# Copyright 2002-2007 Interchange Development Group and others
# 
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.  See the LICENSE file for details.
# 
# $Id: mail.coretag,v 1.5 2007-03-30 23:40:49 pajamian Exp $

UserTag mail                Order        to
UserTag mail                addAttr
UserTag mail                hasEndTag
UserTag mail                PosNumber    1
UserTag mail                Version      $Revision: 1.5 $
UserTag mail                MapRoutine   Vend::Interpolate::tag_mail

Source: lib/Vend/Interpolate.pm
Lines: 2538

sub tag_mail {
  my($to, $opt, $body) = @_;
  my($ok);

my @todo = (
        qw/
          From      
          To       
          Subject   
          Reply-To  
          Errors-To 
        /
);

my $abort;
my $check;

my $setsub = sub {
  my $k = shift;
  return if ! defined $CGI::values{"mv_email_$k"};
  $abort = 1 if ! $::Scratch->{mv_email_enable};
  $check = 1 if $::Scratch->{mv_email_enable};
  return $CGI::values{"mv_email_$k"};
};

my @headers;
my %found;

unless($opt->{raw}) {
  for my $header (@todo) {
    logError("invalid email header: %s", $header)
      if $header =~ /[^-\w]/;
    my $key = lc $header;
    $key =~ tr/-/_/;
    my $val = $opt->{$key} || $setsub->($key); 
    if($key eq 'subject' and ! length($val) ) {
      $val = errmsg('<no subject>');
    }
    next unless length $val;
    $found{$key} = $val;
    $val =~ s/^\s+//;
    $val =~ s/\s+$//;
    $val =~ s/[\r\n]+\s*(\S)/\n\t$1/g;
    push @headers, "$header: $val";
  }
  unless($found{to} or $::Scratch->{mv_email_enable} =~ /\@/) {
    return
      error_opt($opt, "Refuse to send email message with no recipient.");
  }
  elsif (! $found{to}) {
    $::Scratch->{mv_email_enable} =~ s/\s+/ /g;
    $found{to} = $::Scratch->{mv_email_enable};
    push @headers, "To: $::Scratch->{mv_email_enable}";
  }
}

if($opt->{extra}) {
  $opt->{extra} =~ s/^\s+//mg;
  $opt->{extra} =~ s/\s+$//mg;
  push @headers, grep /^\w[-\w]*:/, split /\n/, $opt->{extra};
}

$body ||= $setsub->('body');
unless($body) {
  return error_opt($opt, "Refuse to send email message with no body.");
}

$body = format_auto_transmission($body) if ref $body;

push(@headers, '') if @headers;

return error_opt("mv_email_enable not set, required.") if $abort;
if($check and $found{to} ne $Scratch->{mv_email_enable}) {
  return error_opt(
      "mv_email_enable to address (%s) doesn't match enable (%s)",
      $found{to},
      $Scratch->{mv_email_enable},
    );
}

  SEND: {
  $ok = send_mail(\@headers, $body);
  }

  if (!$ok) {
  close MAIL;
  $body = substr($body, 0, 2000) if length($body) > 2000;
      return error_opt(
        "Unable to send mail using %s\n%s",
        $Vend::Cfg->{SendMailProgram},
        join("\n", @headers, $body),
      );
}

delete $Scratch->{mv_email_enable} if $check;
return if $opt->{hide};
return join("\n", @headers, $body) if $opt->{show};
  return ($opt->{success} || $ok);
}

Source: lib/Vend/Interpolate.pm
Lines: 2538

sub tag_mail {
  my($to, $opt, $body) = @_;
  my($ok);

my @todo = (
        qw/
          From      
          To       
          Subject   
          Reply-To  
          Errors-To 
        /
);

my $abort;
my $check;

my $setsub = sub {
  my $k = shift;
  return if ! defined $CGI::values{"mv_email_$k"};
  $abort = 1 if ! $::Scratch->{mv_email_enable};
  $check = 1 if $::Scratch->{mv_email_enable};
  return $CGI::values{"mv_email_$k"};
};

my @headers;
my %found;

unless($opt->{raw}) {
  for my $header (@todo) {
    logError("invalid email header: %s", $header)
      if $header =~ /[^-\w]/;
    my $key = lc $header;
    $key =~ tr/-/_/;
    my $val = $opt->{$key} || $setsub->($key); 
    if($key eq 'subject' and ! length($val) ) {
      $val = errmsg('<no subject>');
    }
    next unless length $val;
    $found{$key} = $val;
    $val =~ s/^\s+//;
    $val =~ s/\s+$//;
    $val =~ s/[\r\n]+\s*(\S)/\n\t$1/g;
    push @headers, "$header: $val";
  }
  unless($found{to} or $::Scratch->{mv_email_enable} =~ /\@/) {
    return
      error_opt($opt, "Refuse to send email message with no recipient.");
  }
  elsif (! $found{to}) {
    $::Scratch->{mv_email_enable} =~ s/\s+/ /g;
    $found{to} = $::Scratch->{mv_email_enable};
    push @headers, "To: $::Scratch->{mv_email_enable}";
  }
}

if($opt->{extra}) {
  $opt->{extra} =~ s/^\s+//mg;
  $opt->{extra} =~ s/\s+$//mg;
  push @headers, grep /^\w[-\w]*:/, split /\n/, $opt->{extra};
}

$body ||= $setsub->('body');
unless($body) {
  return error_opt($opt, "Refuse to send email message with no body.");
}

$body = format_auto_transmission($body) if ref $body;

push(@headers, '') if @headers;

return error_opt("mv_email_enable not set, required.") if $abort;
if($check and $found{to} ne $Scratch->{mv_email_enable}) {
  return error_opt(
      "mv_email_enable to address (%s) doesn't match enable (%s)",
      $found{to},
      $Scratch->{mv_email_enable},
    );
}

  SEND: {
  $ok = send_mail(\@headers, $body);
  }

  if (!$ok) {
  close MAIL;
  $body = substr($body, 0, 2000) if length($body) > 2000;
      return error_opt(
        "Unable to send mail using %s\n%s",
        $Vend::Cfg->{SendMailProgram},
        join("\n", @headers, $body),
      );
}

delete $Scratch->{mv_email_enable} if $check;
return if $opt->{hide};
return join("\n", @headers, $body) if $opt->{show};
  return ($opt->{success} || $ok);
}

AUTHORS

Interchange Development Group

SEE ALSO

DocBook! Interchange!