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

Clot.email attchment #217

Merged
merged 4 commits into from
Apr 7, 2024
Merged

Clot.email attchment #217

merged 4 commits into from
Apr 7, 2024

Conversation

CerberusLatrans
Copy link
Contributor

Why

Resolves #201

This allows admins to send a lot of different types of attachments to volunteers.

This PR

Converts base64 to bytearraydata (which takes the mime type and data as byte[]) to use simplejavamail api.
Frontend devs need to convert attachment to base 64 before using route.

Verification Steps

Sent emails with jpg, docx, csv, zip, pdf

Copy link
Contributor

@huang0h huang0h left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome work guys! Great job with figuring out how to send attachments 🥳


private EmailAttachment() {}

private static String getFileExtension(String base64Image) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⛏️ We should clean up this method so the variable names and comments better reflect what we're working with, so anybody in the future (including you!) that looks at this code can quickly and clearly understand what the method does.
For example, the variable base64Image doesn't only contain base 64 image data - it could contain base 64 data for any kind of file now, so something more accurate (maybe base64File?) would better communicate what's going on here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding onto that, since this method is getting a file's mime type, could we rename it so it better describe what it's doing - maybe getFileMimeType?

Comment on lines 54 to 58
//String[] data = dataSplit[1].split("/", 2); // Split the image type here (e.g. "image/png")
//if (data.length != 2 || !data[0].equals("image")) {
// // Ensure the encoded data is an image
// return null;
//}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⛏️ Remember to clean up any blocks that are commented out! If you don't need this code, make sure to delete it


try {
// Temporarily writes the image to disk to decode
mimeType = getFileExtension(data);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⛏️ It looks like getFileExtension() could potentially return null, but we don't ever check for that here. Once we call getFileExtension(), we should check if its result is null (in which case we should probably throw an exception) so we deal with the failure as soon as possible, rather than have it break something else down the line.

try {
// Temporarily writes the image to disk to decode
mimeType = getFileExtension(data);
System.out.println(mimeType);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⛏️ Similar to the commented-out blocks of code - make sure to remove any prints before you merge! If you think this information is important enough to print out, we can use the SLogger.java class for more robust logging

Comment on lines 40 to 41
List<AttachmentResource> attachments = sendEmailRequest.getAttachments().stream()
.map(ea -> ea.getAttachmentResource()).collect(Collectors.toList());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

@@ -660,7 +660,7 @@ private SiteEntriesRecord latestSiteEntry(int siteId) {
@Override
public void uploadSiteImage(
JWTData userData, int siteEntryId, UploadSiteImageRequest uploadSiteImageRequest) {
checkEntryExists(siteEntryId);
checkSiteExists(siteEntryId);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❓ Forgot to mention (sorry for the double review 😞) - was there a reason for changing this method? IIRC site images are associated with site entries, not sites, which is why we use checkEntryExists() rather than checkSiteExists()

Copy link
Contributor

@huang0h huang0h left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm!

System.out.println(mimeType);
mimeType = getFileMimeType(data);
if (mimeType==null) {
throw new MalformedParameterException("data");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't know we had this exception, good find!

Comment on lines +1 to +12
{
"systemParams": "darwin-arm64-83",
"modulesFolders": [
"node_modules"
],
"flags": [],
"linkedModules": [],
"topLevelPatterns": [],
"lockfileEntries": {},
"files": [],
"artifacts": {}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔧 If you'd like, you can remove this folder along with package-lock.json and yarn.lock - not sure how these ended up here but they shouldn't affect anything.

Copy link
Contributor

@SurabhiKeesara SurabhiKeesara left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, just a couple of comments

@@ -0,0 +1,105 @@
package com.codeforcommunity.dto.emailer;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the same comments as on reject email

  • avoid using comments and instead focus on good names (which it looks like you have, so you can delete these)
  • baseEncoding validation based on length

String filePath = "/emails/Email.html";

Map<String, String> templateValues = new HashMap<>();
templateValues.put("body", body.replaceAll("\n", "<br />"));
Optional<String> emailBody = emailOperations.getTemplateString(filePath, templateValues);


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super nitpicky but avoid adding extraneous spaces

@CerberusLatrans
Copy link
Contributor Author

Retested both emailing with attachments and rejecting images after merge

@CerberusLatrans CerberusLatrans merged commit 269355e into master Apr 7, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ability to send emails with attachments
3 participants