|
1 | 1 | package com.genexus.internet; |
2 | 2 |
|
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; |
9 | 6 | import java.util.Enumeration; |
10 | 7 | import java.util.Hashtable; |
11 | 8 | import java.util.Properties; |
@@ -357,21 +354,22 @@ private String getAttachmentContentId(Part part) throws MessagingException |
357 | 354 |
|
358 | 355 | private void saveFile(String filename, InputStream input) throws IOException |
359 | 356 | { |
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 | + } |
375 | 373 | } |
376 | 374 |
|
377 | 375 | public String getNextUID() throws GXMailException |
|
0 commit comments