Add shortOriginalSubject to change email template params

Change email templates could make use of the change's current subject,
the change's original subject or the change's shortened current subject.
But they could not use the change's shortened original subject. With
this change that parameter is provided to change email templates.

Change-Id: I6fc393bb9bca9aa0365ebfc47ac34fc326ba5277
diff --git a/Documentation/config-mail.txt b/Documentation/config-mail.txt
index 3b810e0..6bd6b3d 100644
--- a/Documentation/config-mail.txt
+++ b/Documentation/config-mail.txt
@@ -204,6 +204,11 @@
 +
 The subject limited to 72 characters, with an ellipsis if it exceeds that.
 
+$change.shortOriginalSubject::
++
+The original subject limited to 72 characters, with an ellipsis if it exceeds
+that.
+
 $change.ownerEmail::
 +
 The email address of the owner of the change.
diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/mail/send/ChangeEmail.java b/gerrit-server/src/main/java/com/google/gerrit/server/mail/send/ChangeEmail.java
index e862c38..0d9874e 100644
--- a/gerrit-server/src/main/java/com/google/gerrit/server/mail/send/ChangeEmail.java
+++ b/gerrit-server/src/main/java/com/google/gerrit/server/mail/send/ChangeEmail.java
@@ -461,23 +461,19 @@
     soyContextEmailData.put("includeDiff", getIncludeDiff());
 
     Map<String, String> changeData = new HashMap<>();
-    changeData.put("subject", change.getSubject());
-    changeData.put("originalSubject", change.getOriginalSubject());
+
+    String subject = change.getSubject();
+    String originalSubject = change.getOriginalSubject();
+    changeData.put("subject", subject);
+    changeData.put("originalSubject", originalSubject);
+    changeData.put("shortSubject", shortenSubject(subject));
+    changeData.put("shortOriginalSubject", shortenSubject(originalSubject));
+
     changeData.put("ownerName", getNameFor(change.getOwner()));
     changeData.put("ownerEmail", getNameEmailFor(change.getOwner()));
     changeData.put("changeNumber", Integer.toString(change.getChangeId()));
     soyContext.put("change", changeData);
 
-    String subject = change.getSubject();
-    changeData.put("subject", subject);
-    // shortSubject is the subject limited to 63 characters, with an ellipsis if
-    // it exceeds that.
-    if (subject.length() < 73) {
-      changeData.put("shortSubject", subject);
-    } else {
-      changeData.put("shortSubject", subject.substring(0, 69) + "...");
-    }
-
     Map<String, Object> patchSetData = new HashMap<>();
     patchSetData.put("patchSetId", patchSet.getPatchSetId());
     patchSetData.put("refName", patchSet.getRefName());
@@ -504,6 +500,18 @@
     }
   }
 
+  /**
+   * A shortened subject is the subject limited to 72 characters, with an ellipsis if it exceeds
+   * that limit.
+   */
+  private static String shortenSubject(String subject) {
+    if (subject.length() < 73) {
+      return subject;
+    } else {
+      return subject.substring(0, 69) + "...";
+    }
+  }
+
   private Set<String> getEmailsByState(ReviewerStateInternal state) {
     Set<String> reviewers = new TreeSet<>();
     try {