AT&T 2.0.19 Code drop, stage 3
[aaf/authz.git] / auth / auth-batch / src / main / java / org / onap / aaf / auth / actions / EmailPrint.java
1 /**
2  * ============LICENSE_START====================================================
3  * org.onap.aaf
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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====================================================
19  *
20  */
21
22 package org.onap.aaf.auth.actions;
23
24 import java.io.PrintStream;
25
26 import org.onap.aaf.auth.env.AuthzTrans;
27 import org.onap.aaf.auth.layer.Result;
28 import org.onap.aaf.auth.org.Organization;
29
30 public class EmailPrint extends Email {
31
32         private static final int LINE_LENGTH = 100;
33
34         public EmailPrint(String... defaultCC) {
35                 super(defaultCC);
36         }
37
38         /* (non-Javadoc)
39          * @see org.onap.aaf.auth.actions.Email#exec(org.onap.aaf.auth.org.test.Organization, java.lang.StringBuilder)
40          */
41         @Override
42         protected Result<Void> exec(AuthzTrans trans, Organization org, StringBuilder msg) {
43                 PrintStream out = System.out;
44                 boolean first = true;
45                 out.print("To: ");
46                 for(String s: toList) {
47                         if(first) {first = false;}
48                         else {out.print(',');}
49                         out.print(s);
50                 }
51                 out.println();
52                 
53                 first = true;
54                 out.print("CC: ");
55                 for(String s: ccList) {
56                         if(first) {first = false;}
57                         else {out.print(',');}
58                         out.print(s);
59                 }
60                 out.println();
61
62                 out.print("Subject: ");
63                 out.println(subject);
64                 out.println();
65                 boolean go = true;
66                 
67                 for(int start=0, end=LINE_LENGTH;go;start=end,end=Math.min(msg.length(), start+LINE_LENGTH)) {
68                         int ret = msg.indexOf("\n",start+1);
69                         switch(ret) {
70                                 case -1:
71                                         out.println(msg.substring(start,end));
72                                         break;
73                                 case 0:
74                                         end=start+1;
75                                         out.println();
76                                         break;
77                                 default:
78                                         if(ret<end) {
79                                                 end = ret;
80                                         }
81                                         if(end==start+LINE_LENGTH) {
82                                                 // Word-wrapping
83                                                 ret = msg.lastIndexOf(" ", end);
84                                                 if(ret>start && ret<end) {
85                                                         end=ret+1;
86                                                 }
87                                                 out.println(msg.substring(start,end));
88                                         } else {
89                                                 out.print(msg.substring(start,end));
90                                         }
91                         }
92                         go = end<msg.length();
93                 }
94                 return Result.ok();
95
96         }
97
98 }