Skip to content
Merged
Show file tree
Hide file tree
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
65 changes: 65 additions & 0 deletions common/src/main/java/com/genexus/CommonUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -3490,4 +3490,69 @@ public static String Sanitize(String input, HashMap<Character, Character> whiteL
}
return sanitizedInput.toString();
}


public static boolean isKnownContentType(String type)
{
if (type != null)
{
for (int i = 0; i < contentTypes.length; i++)
{
if (contentTypes[i].length >= 2)
{
if (type.equalsIgnoreCase(contentTypes[i][1]))
return true;
}
}
}
return false;
}

public static String getContentFromExt( String extension)
{
if (extension != null)
{
extension = extension.toLowerCase();
for (int i = 0; i < contentTypes.length; i++) {
if (contentTypes[i][0].equals(extension.trim()))
return contentTypes[i][1];
}
}
return null;
}

private static final String contentTypes[][] = {
{"txt" , "text/plain"},
{"rtx" , "text/richtext"},
{"htm" , "text/html"},
{"html" , "text/html"},
{"xml" , "text/xml"},
{"aif" , "audio/x-aiff"},
{"au" , "audio/basic"},
{"wav" , "audio/wav"},
{"bmp" , "image/bmp"},
{"gif" , "image/gif"},
{"jpe" , "image/jpeg"},
{"jpeg" , "image/jpeg"},
{"jpg" , "image/jpeg"},
{"jfif" , "image/pjpeg"},
{"tif" , "image/tiff"},
{"tiff" , "image/tiff"},
{"png" , "image/x-png"},
{"3gp" , "video/3gpp"},
{"3g2" , "video/3gpp2"},
{"mpg" , "video/mpeg"},
{"mpeg" , "video/mpeg"},
{"mov" , "video/quicktime"},
{"qt" , "video/quicktime"},
{"avi" , "video/x-msvideo"},
{"exe" , "application/octet-stream"},
{"dll" , "application/x-msdownload"},
{"ps" , "application/postscript"},
{"pdf" , "application/pdf"},
{"svg" , "image/svg+xml"},
{"tgz" , "application/x-compressed"},
{"zip" , "application/x-zip-compressed"},
{"gz" , "application/x-gzip"}
};
}
23 changes: 19 additions & 4 deletions gxmail/src/main/java/com/genexus/internet/SMTPSessionJavaMail.java
Original file line number Diff line number Diff line change
Expand Up @@ -217,16 +217,31 @@ private void addAttachment(Multipart multipart, String fileNamePath, String atta
{
fileNamePath = attachDir + fileNamePath;
}
BodyPart messageBodyPart = new MimeBodyPart();
DataSource source = new FileDataSource(fileNamePath);
messageBodyPart.setDataHandler(new DataHandler(source));

if (filename.lastIndexOf(File.separator) != -1)
{
filename = filename.substring(filename.lastIndexOf(File.separator) + 1);
}

int lastDot = filename.lastIndexOf('.');
String extension = (lastDot == -1) ? "" : filename.substring(lastDot + 1).toLowerCase();

String mt = CommonUtil.getContentFromExt(extension);
final String mimeType = (mt == null || mt.isEmpty()) ? "application/octet-stream" : mt;

DataSource source = new FileDataSource(fileNamePath) {
@Override
public String getContentType() {
return mimeType;
}
};

BodyPart messageBodyPart = new MimeBodyPart();
messageBodyPart.setDataHandler(new DataHandler(source));
messageBodyPart.setFileName(filename);

multipart.addBodyPart(messageBodyPart);
}
}

public void logout(GXSMTPSession sessionInfo)
{
Expand Down
59 changes: 2 additions & 57 deletions java/src/main/java/com/genexus/internet/HttpContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -877,31 +877,12 @@ public boolean checkContentType(String contentKey, String contentType, String fu

public static boolean isKnownContentType(String type)
{
if (type != null)
{
for (int i = 0; i < contentTypes.length; i++)
{
if (contentTypes[i].length >= 2)
{
if (type.equalsIgnoreCase(contentTypes[i][1]))
return true;
}
}
}
return false;
return CommonUtil.isKnownContentType(type);
}

public static String getContentFromExt( String extension)
{
if (extension != null)
{
extension = extension.toLowerCase();
for (int i = 0; i < contentTypes.length; i++) {
if (contentTypes[i][0].equals(extension.trim()))
return contentTypes[i][1];
}
}
return null;
return CommonUtil.getContentFromExt(extension);
}

int GX_NULL_TIMEZONEOFFSET = 9999;
Expand All @@ -913,42 +894,6 @@ public void setRestService()

public boolean isRestService()
{ return restService; }

private static final String contentTypes[][] = {
{"txt" , "text/plain"},
{"rtx" , "text/richtext"},
{"htm" , "text/html"},
{"html" , "text/html"},
{"xml" , "application/xml"},
{"aif" , "audio/x-aiff"},
{"au" , "audio/basic"},
{"wav" , "audio/wav"},
{"bmp" , "image/bmp"},
{"gif" , "image/gif"},
{"jpe" , "image/jpeg"},
{"jpeg" , "image/jpeg"},
{"jpg" , "image/jpeg"},
{"jfif" , "image/pjpeg"},
{"tif" , "image/tiff"},
{"tiff" , "image/tiff"},
{"png" , "image/x-png"},
{"3gp" , "video/3gpp"},
{"3g2" , "video/3gpp2"},
{"mpg" , "video/mpeg"},
{"mpeg" , "video/mpeg"},
{"mov" , "video/quicktime"},
{"qt" , "video/quicktime"},
{"avi" , "video/x-msvideo"},
{"exe" , "application/octet-stream"},
{"dll" , "application/x-msdownload"},
{"ps" , "application/postscript"},
{"pdf" , "application/pdf"},
{"svg" , "image/svg+xml"},
{"tgz" , "application/x-compressed"},
{"zip" , "application/x-zip-compressed"},
{"gz" , "application/x-gzip"},
{"json" , "application/json"}
};

public boolean willRedirect()
{
Expand Down
Loading