[Rt-commit] r8858 - rt/branches/3.7-EXPERIMENTAL/lib/RT/Interface

ruz at bestpractical.com ruz at bestpractical.com
Fri Aug 31 09:01:09 EDT 2007


Author: ruz
Date: Fri Aug 31 09:01:09 2007
New Revision: 8858

Modified:
   rt/branches/3.7-EXPERIMENTAL/lib/RT/Interface/Email.pm

Log:
::Interface::Email
* return a template from PrepareEmailUsingTemplate instead of mime object,
  so caller can check that message was empty and behave accordingly
  

Modified: rt/branches/3.7-EXPERIMENTAL/lib/RT/Interface/Email.pm
==============================================================================
--- rt/branches/3.7-EXPERIMENTAL/lib/RT/Interface/Email.pm	(original)
+++ rt/branches/3.7-EXPERIMENTAL/lib/RT/Interface/Email.pm	Fri Aug 31 09:01:09 2007
@@ -470,8 +470,11 @@
 
 =head2 PrepareEmailUsingTemplate Template => '', Arguments => {}
 
-Loads a template and parses it using arguments. Returns a L<MIME::Entity>
-object or undef on errors.
+Loads a template. Parses it using arguments if it's not empty.
+Returns a tuple (L<RT::Template> object, error message).
+
+Note that even if a template object is returned MIMEObj method
+may return undef for empty templates.
 
 =cut
 
@@ -485,12 +488,14 @@
     my $template = RT::Template->new( $RT::SystemUser );
     $template->LoadGlobalTemplate( $args{'Template'} );
     unless ( $template->id ) {
-        $RT::Logger->error("Couldn't load template '". $args{'Template'} ."'");
-        return (undef);
+        return (undef, "Couldn't load template '". $args{'Template'} ."'");
     }
-    $template->Parse( %{ $args{'Arguments'} } );
+    return $template if $template->IsEmpty;
+
+    my ($status, $msg) = $template->Parse( %{ $args{'Arguments'} } );
+    return (undef, $msg) unless $status;
 
-    return $template->MIMEObj;
+    return $template;
 }
 
 =head2 SendEmailUsingTemplate Template => '', Arguments => {}, To => '', Cc => '', Bcc => ''


More information about the Rt-commit mailing list