From 62853dfd714d40a6816377afa093bbf2eb1dfdd7 Mon Sep 17 00:00:00 2001
From: srosse <none@none>
Date: Mon, 4 Feb 2013 14:41:07 +0100
Subject: [PATCH] OO-527: use the variables in the context of mail template too

---
 .../org/olat/core/util/mail/MailerWithTemplate.java   | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/src/main/java/org/olat/core/util/mail/MailerWithTemplate.java b/src/main/java/org/olat/core/util/mail/MailerWithTemplate.java
index d1b08178015..8c8bc802229 100644
--- a/src/main/java/org/olat/core/util/mail/MailerWithTemplate.java
+++ b/src/main/java/org/olat/core/util/mail/MailerWithTemplate.java
@@ -164,7 +164,7 @@ public class MailerWithTemplate {
 		if (recipientsTO != null) {
 			for (Identity recipient : recipientsTO) {
 				// populate velocity context with variables
-				VelocityContext context = new VelocityContext();
+				VelocityContext context = getContext(template);
 				template.putVariablesInMailContext(context, recipient);
 				sendWithContext(context, mCtxt, metaId, recipient, template, sender, result);
 				if (!result.getFailedIdentites().contains(recipient)) {
@@ -177,7 +177,7 @@ public class MailerWithTemplate {
 				List<Identity> cc = new ArrayList<Identity>();
 				cc.add(recipient);
 				// populate velocity context with variables
-				VelocityContext context = new VelocityContext();
+				VelocityContext context = getContext(template);
 				template.putVariablesInMailContext(context, recipient);
 				sendWithContext(context, mCtxt, metaId, recipient, template, sender, result);
 			}
@@ -191,6 +191,13 @@ public class MailerWithTemplate {
 		return result;
 	}
 	
+	private VelocityContext getContext(MailTemplate template) {
+		if(template != null && template.getContext() != null) {
+			return new VelocityContext(template.getContext());
+		}
+		return new VelocityContext();
+	}
+	
 	/**
 	 * may return null, but then the result.getReturnCode != OK... so check the
 	 * result code.
-- 
GitLab