-
Notifications
You must be signed in to change notification settings - Fork 2
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
Clot.email attchment #217
Changes from all commits
fbf0caa
ebcbcdb
fd44a53
d951a4a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,14 @@ | ||
package com.codeforcommunity.dto.emailer; | ||
|
||
import com.codeforcommunity.aws.EncodedImage; | ||
import com.codeforcommunity.dto.ApiDto; | ||
import com.codeforcommunity.exceptions.BadRequestImageException; | ||
import com.codeforcommunity.exceptions.HandledException; | ||
import com.codeforcommunity.exceptions.MalformedParameterException; | ||
|
||
import org.simplejavamail.api.email.AttachmentResource; | ||
|
||
import javax.mail.util.ByteArrayDataSource; | ||
import java.io.File; | ||
import java.io.FileOutputStream; | ||
import java.io.IOException; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Base64; | ||
import java.util.List; | ||
|
@@ -26,12 +24,12 @@ public EmailAttachment(String name, String data) { | |
|
||
private EmailAttachment() {} | ||
|
||
private static String getFileExtension(String base64Image) { | ||
if (base64Image == null || base64Image.length() < 10) { | ||
private static String getFileMimeType(String base64File) { | ||
if (base64File == null || base64File.length() < 10) { | ||
return null; | ||
} | ||
|
||
String[] base64ImageSplit = base64Image.split(",", 2); | ||
String[] base64ImageSplit = base64File.split(",", 2); | ||
if (base64ImageSplit.length != 2) { | ||
return null; | ||
} | ||
|
@@ -44,24 +42,24 @@ private static String getFileExtension(String base64Image) { | |
} | ||
|
||
String[] dataSplit = metaSplit[0].split(":", 2); | ||
if (dataSplit.length != 2) { | ||
return null; | ||
} | ||
|
||
String[] data = dataSplit[1].split("/", 2); | ||
if (data.length != 2 || !data[0].equals("image")) { | ||
if (dataSplit.length != 2) { | ||
return null; | ||
} | ||
|
||
String fileExtension = data[1]; | ||
String fileExtension = dataSplit[1]; | ||
return fileExtension; | ||
} | ||
private static ByteArrayDataSource stringToDataSource(String data) { | ||
byte[] imageData; | ||
String mimeType; | ||
|
||
try { | ||
mimeType = getFileExtension(data); | ||
mimeType = getFileMimeType(data); | ||
if (mimeType==null) { | ||
throw new MalformedParameterException("data"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Didn't know we had this exception, good find! |
||
} | ||
|
||
String[] base64Split = data.split(",", 2); | ||
imageData = Base64.getDecoder().decode(base64Split[1]); | ||
|
||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. | ||
# yarn lockfile v1 | ||
|
||
|
There was a problem hiding this comment.
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