Skip to content

Commit bfdc16a

Browse files
Fix attachment download and empty subject when working with POP3 (#858)
(cherry picked from commit 7c1028d)
1 parent 736f16b commit bfdc16a

File tree

2 files changed

+22
-21
lines changed

2 files changed

+22
-21
lines changed

common/src/main/java/com/genexus/internet/JapaneseMimeDecoder.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ public class JapaneseMimeDecoder
88

99
public static String decode(String encoded)
1010
{
11+
if (encoded == null)
12+
return "";
13+
1114
int strLen = encoded.length();
1215
int currentIndex = 0;
1316

gxmail/src/main/java/com/genexus/internet/POP3SessionJavaMail.java

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
package com.genexus.internet;
22

3-
import java.io.BufferedInputStream;
4-
import java.io.BufferedOutputStream;
5-
import java.io.File;
6-
import java.io.FileOutputStream;
7-
import java.io.IOException;
8-
import java.io.InputStream;
3+
import java.io.*;
4+
import java.net.URLEncoder;
5+
import java.nio.charset.StandardCharsets;
96
import java.util.Enumeration;
107
import java.util.Hashtable;
118
import java.util.Properties;
@@ -357,21 +354,22 @@ private String getAttachmentContentId(Part part) throws MessagingException
357354

358355
private void saveFile(String filename, InputStream input) throws IOException
359356
{
360-
File file = new File(attachmentsPath + filename);
361-
BufferedOutputStream bos;
362-
try (FileOutputStream fos = new FileOutputStream(file)) {
363-
bos = new BufferedOutputStream(fos);
364-
}
365-
366-
BufferedInputStream bis = new BufferedInputStream(input);
367-
int aByte;
368-
while ((aByte = bis.read()) != -1)
369-
{
370-
bos.write(aByte);
371-
}
372-
bos.flush();
373-
bos.close();
374-
bis.close();
357+
try {
358+
String encodedFilename = URLEncoder.encode(filename, StandardCharsets.UTF_8.toString());
359+
encodedFilename = encodedFilename.replace("+", "_");
360+
File file = new File(attachmentsPath + encodedFilename);
361+
try (FileOutputStream fos = new FileOutputStream(file);
362+
BufferedOutputStream bos = new BufferedOutputStream(fos);
363+
BufferedInputStream bis = new BufferedInputStream(input)) {
364+
int aByte;
365+
while ((aByte = bis.read()) != -1) {
366+
bos.write(aByte);
367+
}
368+
bos.flush();
369+
}
370+
} catch (UnsupportedEncodingException e) {
371+
throw new IOException("Error encoding the filename", e);
372+
}
375373
}
376374

377375
public String getNextUID() throws GXMailException

0 commit comments

Comments
 (0)