]> git.etc.gen.nz Git - mail-merge.git/commitdiff
Make the subject templatable master
authorAndrew Ruthven <puck@catalystcloud.nz>
Mon, 27 Jun 2022 09:44:42 +0000 (21:44 +1200)
committerAndrew Ruthven <puck@catalyst.net.nz>
Mon, 27 Jun 2022 09:53:48 +0000 (21:53 +1200)
merge.pl

index 75357cf0cd962b7efb0150d5bf28db606b46d361..f7555d6732c14cc396a58a2063f882aa899c58d2 100755 (executable)
--- a/merge.pl
+++ b/merge.pl
@@ -163,6 +163,15 @@ sub merge_message {
   }
 
   # Do the merge.
+  my $subject;
+  if (! $tt->process(\$tmplData->{'subject'}, $cols, \$subject)) {
+    warn "Failed to process template: " . $tt->error();
+    warn "Template: $tmplData->{'subject'}\n"
+      if $verbose;
+
+    next;
+  }
+
   my $out;
   if (! $tt->process(\$tmplData->{'body'}, $cols, \$out)) {
     warn "Failed to process template: " . $tt->error();
@@ -192,7 +201,7 @@ sub merge_message {
   }
 
   if ($verbose) {
-    print "Subject: $tmplData->{'subject'}\n";
+    print "Subject: $subject\n";
     print "From: $tmplData->{'from'}\n";
     print "Attachment: $file_to_attach\n" if defined $file_to_attach;
     print $out;
@@ -228,7 +237,7 @@ sub merge_message {
     my $mail = MIME::Entity->build(
        To        => \@emails,
        From      => $tmplData->{'from'},
-       Subject   => $tmplData->{'subject'},
+       Subject   => $subject,
        Bcc       => $tmplData->{'bcc'},
        Cc        => $tmplData->{'bc'},
        'Reply-To' => $tmplData->{'reply_to'},