Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added if condition for hasAttachments #6

Merged
merged 2 commits into from
Oct 30, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions src/main/java/me/shivzee/JMailTM.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.stream.Collectors;


/***
Expand Down Expand Up @@ -103,10 +104,10 @@ private Message messageUtility(JSONObject json) throws ParseException, DateTimeP

List<Receiver> receivers = new ArrayList<>();
JSONArray receiverArray = (JSONArray) parser.parse(json.get("to").toString());
Object [] rArray = receiverArray.toArray();
for(Object jsonObject : rArray){
Object[] rArray = receiverArray.toArray();
for (Object jsonObject : rArray) {
JSONObject object = (JSONObject) jsonObject;
receivers.add(new Receiver(object.get("address").toString() , object.get("name").toString()));
receivers.add(new Receiver(object.get("address").toString(), object.get("name").toString()));
}
String subject = json.get("subject").toString();
String content = json.get("text").toString();
Expand All @@ -118,11 +119,14 @@ private Message messageUtility(JSONObject json) throws ParseException, DateTimeP
String rawHTML = json.get("html").toString();
boolean hasAttachments = (boolean) json.get("hasAttachments");

List<Attachment> attachments = new ArrayList<>();
JSONArray attachmentArray = (JSONArray) parser.parse(json.get("attachments").toString());
Object [] aArray = attachmentArray.toArray();
Object[] aArray = new Object[0];
if (hasAttachments) {
JSONArray attachmentArray = (JSONArray) parser.parse(json.get("attachments").toString());
aArray = attachmentArray.toArray();
}

for(Object attachmentObject : aArray){
List<Attachment> attachments = new ArrayList<>();
for (Object attachmentObject : aArray) {
JSONObject object = (JSONObject) attachmentObject;
String aId = object.get("id").toString();
String aFilename = object.get("filename").toString();
Expand All @@ -132,18 +136,18 @@ private Message messageUtility(JSONObject json) throws ParseException, DateTimeP
boolean aRelated = (boolean) object.get("related");
long aSize = Long.parseLong(object.get("size").toString());
String aDownloadUrl = object.get("downloadUrl").toString();
attachments.add(new Attachment(aId , aFilename , aContentType , aDisposition, aTransferEncoding ,aRelated ,aSize , aDownloadUrl ,bearerToken));
attachments.add(new Attachment(aId, aFilename, aContentType, aDisposition, aTransferEncoding, aRelated, aSize, aDownloadUrl, bearerToken));
}

long size = Long.parseLong(json.get("size").toString());
String downloadUrl = json.get("downloadUrl").toString();
String createdAt = json.get("createdAt").toString();
String updatedAt = json.get("updatedAt").toString();

ZonedDateTime createdDateTime = Utility.parseToDefaultTimeZone(createdAt,"yyyy-MM-dd'T'HH:mm:ss'+00:00'");
ZonedDateTime updatedDateTime = Utility.parseToDefaultTimeZone(updatedAt,"yyyy-MM-dd'T'HH:mm:ss'+00:00'");
ZonedDateTime createdDateTime = Utility.parseToDefaultTimeZone(createdAt, "yyyy-MM-dd'T'HH:mm:ss'+00:00'");
ZonedDateTime updatedDateTime = Utility.parseToDefaultTimeZone(updatedAt, "yyyy-MM-dd'T'HH:mm:ss'+00:00'");

return new Message(id,msgid,senderAddress,senderName,receivers,subject,content,seen,flagged,isDeleted,retention,retentionDate,rawHTML,hasAttachments,attachments,size,downloadUrl,createdAt,createdDateTime,updatedAt,updatedDateTime,bearerToken,json.toJSONString());
return new Message(id, msgid, senderAddress, senderName, receivers, subject, content, seen, flagged, isDeleted, retention, retentionDate, rawHTML, hasAttachments, attachments, size, downloadUrl, createdAt, createdDateTime, updatedAt, updatedDateTime, bearerToken, json.toJSONString());
}

/**
Expand Down