Skip to content

Commit

Permalink
Merge pull request #98 from cal-itp/bugfix/generalize-sendgrid
Browse files Browse the repository at this point in the history
resolve changes to sendgrid.java that served only graas report
  • Loading branch information
owades authored Feb 10, 2022
2 parents 8bbdde8 + e2cc92e commit 68cc450
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions gtfu/src/main/java/gtfu/tools/SendGrid.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ public class SendGrid {
private String[] tos;
private String subject;
private String body;
private Map<String, byte[]> blobMap;
private Map<String, byte[]> imageMap;

public SendGrid(String[] recipients, String emailSubject, String body, Map<String, byte[]> images) {
public SendGrid(String[] recipients, String emailSubject, String body, Map<String, byte[]> imageMap) {
this.tos = recipients;
this.subject = emailSubject;
this.body = escape(body);
this.blobMap = images;
this.imageMap = imageMap;
}

private String escape(String s) {
Expand Down Expand Up @@ -54,8 +54,8 @@ private String makeTos() {
private String makeAttachments() {
StringBuffer sb = new StringBuffer();

for (String key : blobMap.keySet()) {
byte[] buf = blobMap.get(key);
for (String key : imageMap.keySet()) {
byte[] buf = imageMap.get(key);

if (sb.length() > 0) {
sb.append(',');
Expand All @@ -74,11 +74,12 @@ private String makeAttachments() {

public int send() {
String attach = "";

if (blobMap.size() > 0) {
attach = String.format(",\"attachments\": [%s]", makeAttachments());
} else{
body = "There are no files in today's GRaaS report";
if(imageMap != null){
if (imageMap.size() > 0) {
attach = String.format(",\"attachments\": [%s]", makeAttachments());
} else{
body = "There are no images attached";
}
}

String from = "[email protected]";
Expand Down

0 comments on commit 68cc450

Please sign in to comment.