EmailChallenge: add requester's certificate name into the email content

Change-Id: I3231640daf0daa9edbac1fea694fbbbdcdb353fa
diff --git a/ndncert-mail.conf.sample b/ndncert-mail.conf.sample
index 492c1e5..a33e458 100644
--- a/ndncert-mail.conf.sample
+++ b/ndncert-mail.conf.sample
@@ -8,5 +8,5 @@
 [ndncert_email_settings]
 MAIL_FROM = NDN Testbed Certificate Robot <noreply-ndncert@named-data.net>
 SUBJECT = Email Challenge Triggered by NDNCERT
-TEXT_TEMPLATE = Your PIN code: {0} from NDNCERT CA {1}. Please keep it secret and type in to your application to finish the certificiate issuance process. If you do not know what is going on, please ignore the message.
-HTML_TEMPLATE = <html><head></head><body><p><b>Your PIN code: {0} from NDNCERT CA {1}</b></p><p>Please keep it secret and type in to your application to finish the certificiate issuance process. If you do not know what is going on, please ignore the message.</p><p>Sincerely,<br/>NDN Testbed NDNCERT robot</p>
\ No newline at end of file
+TEXT_TEMPLATE = Your PIN code: {0} from NDNCERT CA {1}. Certificate Name: {2}. Your email has been used to apply for a digital certificate from NDNCERT. Please keep it secret and type in to your application to finish the certificiate issuance process. If you do not know what is going on, please ignore the message.
+HTML_TEMPLATE = <html><head></head><body><p><b>Your PIN code: {0} from NDNCERT CA {1}. Certificate Name: {2}.</b></p><p>Your email has been used to apply for a digital certificate from NDNCERT. Please keep it secret and type in to your application to finish the certificiate issuance process. If you do not know what is going on, please ignore the message.</p><p>Sincerely,<br/>NDN Testbed NDNCERT robot</p>
\ No newline at end of file
diff --git a/ndncert-send-email-challenge.py b/ndncert-send-email-challenge.py
index 1916791..df9ca4d 100755
--- a/ndncert-send-email-challenge.py
+++ b/ndncert-send-email-challenge.py
@@ -14,6 +14,7 @@
 parser.add_argument("email", help="the receiver email address")
 parser.add_argument("secret", help="the secret of the challenge")
 parser.add_argument("caName", help="the CA name")
+parser.add_argument("certName", help="the Ceritifcate being requested")
 args = parser.parse_args()
 
 # open config
@@ -30,8 +31,8 @@
 # read email settings
 msg_from = confParser.get('ndncert_email_settings', 'MAIL_FROM')
 subject = confParser.get('ndncert_email_settings', 'SUBJECT')
-text = confParser.get('ndncert_email_settings', 'TEXT_TEMPLATE').format(args.secret, args.caName)
-html = confParser.get('ndncert_email_settings', 'HTML_TEMPLATE').format(args.secret, args.caName)
+text = confParser.get('ndncert_email_settings', 'TEXT_TEMPLATE').format(args.secret, args.caName, args.certName)
+html = confParser.get('ndncert_email_settings', 'HTML_TEMPLATE').format(args.secret, args.caName, args.certName)
 
 # form email message
 msg = MIMEMultipart('alternative')
diff --git a/src/challenge-module/challenge-email.cpp b/src/challenge-module/challenge-email.cpp
index dbd3b2c..8c49726 100644
--- a/src/challenge-module/challenge-email.cpp
+++ b/src/challenge-module/challenge-email.cpp
@@ -175,7 +175,8 @@
                           const CertificateRequest& request) const
 {
   std::string command = m_sendEmailScript;
-  command += " \"" + emailAddress + "\" \"" + secret + "\" \"" + request.m_caName.toUri() + "\"";
+  command += " \"" + emailAddress + "\" \"" + secret + "\" \""
+    + request.m_caName.toUri() + "\" \"" + request.m_cert.getName().toUri()  + "\"";
   int result = system(command.c_str());
   if (result == -1) {
     _LOG_TRACE("EmailSending Script " + m_sendEmailScript + " fails.");
diff --git a/tests/unit-tests/challenge-email.t.cpp b/tests/unit-tests/challenge-email.t.cpp
index 3b9850c..af86a5f 100644
--- a/tests/unit-tests/challenge-email.t.cpp
+++ b/tests/unit-tests/challenge-email.t.cpp
@@ -64,17 +64,28 @@
   std::string line = "";
   std::string delimiter = " ";
   std::ifstream emailFile("tmp.txt");
-  if (emailFile.is_open())
-  {
+  if (emailFile.is_open()) {
     getline(emailFile, line);
     emailFile.close();
   }
-  std::string recipientEmail = line.substr(0, line.find(delimiter));
-  std::string secret = line.substr(line.find(delimiter) + 1);
-
+  int end = line.find(delimiter);
+  std::string recipientEmail = line.substr(0, end);
   BOOST_CHECK_EQUAL(recipientEmail, "zhiyi@cs.ucla.edu");
+  line = line.substr(end + 1);
+
+  end = line.find(delimiter);
+  std::string secret = line.substr(0, end);
   auto stored_secret = request.m_challengeSecrets.get<std::string>(ChallengeEmail::JSON_CODE);
   BOOST_CHECK_EQUAL(secret, stored_secret);
+  line = line.substr(end + 1);
+
+  end = line.find(delimiter);
+  std::string caName = line.substr(0, end);
+  BOOST_CHECK_EQUAL(caName, Name("/ndn/site1"));
+  line = line.substr(end + 1);
+
+  std::string certName = line;
+  BOOST_CHECK_EQUAL(certName, cert.getName().toUri());
   std::remove("tmp.txt");
 }
 
diff --git a/tests/unit-tests/test-send-email.sh b/tests/unit-tests/test-send-email.sh
index 901d057..077908b 100755
--- a/tests/unit-tests/test-send-email.sh
+++ b/tests/unit-tests/test-send-email.sh
@@ -2,7 +2,10 @@
 
 RECEIVER=$1
 SECRET=$2
+CANAME=$3
+CERTNAME=$4
 
-MESSAGE=$RECEIVER" "$SECRET
+MESSAGE=$RECEIVER" "$SECRET" "$CANAME" "$CERTNAME
 
 echo $MESSAGE > tmp.txt
+echo $MESSAGE