debugging output change in send_email
[freeside.git] / FS / FS / Misc.pm
index 1bb1ae1..98490ac 100644 (file)
@@ -4,6 +4,7 @@ use strict;
 use vars qw ( @ISA @EXPORT_OK $DEBUG );
 use Exporter;
 use Carp;
+use Data::Dumper;
 
 @ISA = qw( Exporter );
 @EXPORT_OK = qw( send_email send_fax );
@@ -69,6 +70,12 @@ FS::UID->install_callback( sub {
 
 sub send_email {
   my(%options) = @_;
+  if ( $DEBUG ) {
+    my %doptions = %options;
+    $doptions{'body'} = '(full body not shown in debug)';
+    warn "FS::Misc::send_email called with options:\n  ". Dumper(\%doptions);
+#         join("\n", map { "  $_: ". $options{$_} } keys %options ). "\n"
+  }
 
   $ENV{MAILADDRESS} = $options{'from'};
   my $to = ref($options{to}) ? join(', ', @{ $options{to} } ) : $options{to};
@@ -118,8 +125,15 @@ sub send_email {
 
   }
 
-  $options{'from'} =~ /\@([\w\.\-]+)/ or $1 = 'example.com';
-  my $message_id = join('.', rand()*(2**32), $$, time). "\@$1";
+  my $domain;
+  if ( $options{'from'} =~ /\@([\w\.\-]+)/ ) {
+    $domain = $1;
+  } else {
+    warn 'no domain found in invoice from address '. $options{'from'}.
+         '; constructing Message-ID @example.com'; 
+    $domain = 'example.com';
+  }
+  my $message_id = join('.', rand()*(2**32), $$, time). "\@$domain";
 
   my $message = MIME::Entity->build(
     'From'       => $options{'from'},