1 # Copyright 2002-2007 Interchange Development Group and others
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version. See the LICENSE file for details.
8 # $Id: email_raw.tag,v 1.8 2007-03-30 23:40:56 pajamian Exp $
10 UserTag email-raw hasEndTag
11 UserTag email-raw addAttr
12 UserTag email-raw Interpolate
13 UserTag email-raw Version $Revision: 1.8 $
14 UserTag email-raw Routine <<EOR
20 # If configured, intercept all outgoing email and re-route
22 my $intercept = $::Variable->{MV_EMAIL_INTERCEPT}
23 || $Global::Variable->{MV_EMAIL_INTERCEPT}
25 $body =~ s/\A(.*?)\r?\n\r?\n//s;
26 my $header_block = $1;
27 # unfold valid RFC 2822 "2.2.3. Long Header Fields"
28 $header_block =~ s/\r?\n([ \t]+)/$1/g;
30 for (split /\r?\n/, $header_block) {
31 if (my ($header, $value) = /^(To|Cc|Bcc):\s*(.+)/si) {
33 "Intercepting outgoing email (%s: %s) and instead sending to '%s'",
34 $header, $value, $intercept
36 $_ = "$header: $intercept";
37 push @headers, "X-Intercepted-$header: $value";
41 $body = join("\n", @headers) . "\n\n" . $body;
45 my $using = $Vend::Cfg->{SendMailProgram};
47 if (lc $using eq 'none') {
50 } elsif (lc $using eq 'net::smtp') {
51 $body =~ s/^(.+?)(?:\r?\n){2}//s;
53 last SEND unless $headers;
54 my @head = split(/\r?\n/,$headers);
55 $ok = send_mail(\@head,$body);
57 open(Vend::MAIL,"|$using -t") or last SEND;
58 print Vend::MAIL $body
67 ::logError("Unable to send mail using $Vend::Cfg->{SendMailProgram}\n" .
68 "Message follows:\n\n$body");
71 return $opt->{hide} ? '' : $ok;