2 * ============LICENSE_START====================================================
4 * ===========================================================================
5 * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
6 * ===========================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END====================================================
21 package org.onap.aaf.auth.org;
23 import java.io.BufferedWriter;
24 import java.io.IOException;
25 import java.nio.file.Files;
26 import java.nio.file.Path;
27 import java.nio.file.Paths;
28 import java.util.List;
30 import org.onap.aaf.auth.env.AuthzTrans;
31 import org.onap.aaf.cadi.Access;
32 import org.onap.aaf.misc.env.APIException;
33 import org.onap.aaf.misc.env.util.Chrono;
35 public class FileMailer implements Mailer {
37 private String mail_from;
38 private String testName;
42 public FileMailer(Access access) throws APIException {
45 mail_from = access.getProperty("MAIL_FROM", null);
47 throw new APIException("MAIL_FROM property is required for Email Notifications");
49 String env = access.getProperty("CASS_ENV", "UNKNOWN");
50 String logdir = access.getProperty(env+".LOG_DIR", "logs/"+env);
51 dir = Paths.get(logdir+"/email/"+Chrono.dateOnlyStamp());
52 if(!Files.exists(dir)) {
54 Files.createDirectories(dir);
55 } catch (IOException e) {
56 throw new APIException("Cannot create directory: " + dir.toString(),e);
60 boolean dryrun = Boolean.parseBoolean(access.getProperty("DRY_RUN","false"));
61 int maxEmail = Integer.parseInt(access.getProperty("MAX_EMAIL", "-1"));
62 if(dryrun && maxEmail==1) {
63 testName = "email_test";
70 public boolean sendEmail(AuthzTrans trans, String test, List<String> toList, List<String> ccList,
71 String subject, String body, Boolean urgent) throws OrganizationException {
72 boolean status = false;
76 path = Files.createTempFile(dir, "email", ".hdr");
78 path = Paths.get(dir.toString(), "emailTEST"+test+".hdr");
80 BufferedWriter bw = Files.newBufferedWriter(path);
84 for(String to : toList) {
96 for(String cc : ccList) {
110 bw.write("SUBJECT: ");
115 bw.write("Importance: High");
123 path = Paths.get(path.toString().replaceAll(".hdr", ".html"));
124 bw = Files.newBufferedWriter(path);
132 } catch ( IOException e) {
133 throw new OrganizationException(e);
140 public String mailFrom() {