/** * Copyright 2016 Google Inc. All Rights Reserved. * *
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of the License at * *
http://www.apache.org/licenses/LICENSE-2.0 * *
Unless required by applicable law or agreed to in writing, software distributed under the
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.vts.util;
import com.android.vts.entity.DeviceInfoEntity;
import com.android.vts.entity.TestRunEntity;
import com.android.vts.entity.UserFavoriteEntity;
import com.google.appengine.api.datastore.DatastoreService;
import com.google.appengine.api.datastore.DatastoreServiceFactory;
import com.google.appengine.api.datastore.Entity;
import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.Query;
import com.google.appengine.api.datastore.Query.Filter;
import com.google.appengine.api.datastore.Query.FilterOperator;
import com.google.appengine.api.datastore.Query.FilterPredicate;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Optional;
import java.util.Properties;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import org.apache.commons.lang.StringUtils;
/** EmailHelper, a helper class for building and sending emails. */
public class EmailHelper {
protected static final Logger logger = Logger.getLogger(EmailHelper.class.getName());
protected static String DEFAULT_EMAIL;
protected static String EMAIL_DOMAIN;
protected static String SENDER_EMAIL;
private static final String VTS_EMAIL_NAME = "VTS Alert Bot";
public static void setPropertyValues(Properties systemConfigProp) {
DEFAULT_EMAIL = systemConfigProp.getProperty("appengine.defaultEmail");
EMAIL_DOMAIN = systemConfigProp.getProperty("appengine.emailDomain");
SENDER_EMAIL = systemConfigProp.getProperty("appengine.senderEmail");
}
/**
* Create an email footer with the information from the test run.
*
* @param testRun The TestRunEntity containing test run metadata, or null.
* @param devices The list of devices whose fingerprints to include in the email, or null.
* @param link A link to the Dashboard page containing more information.
* @return The String email footer.
*/
public static String getEmailFooter(
TestRunEntity testRun, List
");
if (devices != null) {
for (DeviceInfoEntity device : devices) {
sb.append("Device: " + device.getFingerprint() + "
");
}
}
if (testRun != null) {
sb.append("VTS Build ID: " + testRun.getTestBuildId() + "
");
sb.append("Start Time: " + TimeUtil.getDateTimeZoneString(testRun.getStartTimestamp()));
sb.append("
End Time: " + TimeUtil.getDateTimeZoneString(testRun.getEndTimestamp()));
}
sb.append(
"
For details, visit the"
+ " "
+ "VTS dashboard.");
return sb.toString();
}
/**
* Fetches the list of subscriber email addresses for a test.
*
* @param testKey The key for the test for which to fetch the email addresses.
* @returns List of email addresses (String).
* @throws IOException
*/
public static List