|
4 | 4 | import org.jetbrains.annotations.NotNull; |
5 | 5 | import org.jetbrains.annotations.Nullable; |
6 | 6 | import org.simplejavamail.internal.util.MiscUtil; |
| 7 | +import org.simplejavamail.internal.util.NamedDataSource; |
7 | 8 | import org.simplejavamail.internal.util.NaturalEntryKeyComparator; |
8 | 9 | import org.simplejavamail.internal.util.Preconditions; |
9 | 10 |
|
@@ -385,21 +386,14 @@ public static DataHandler retrieveDataHandler(@NotNull final MimePart part) { |
385 | 386 | private static DataSource createDataSource(@NotNull final MimePart part, final boolean fetchAttachmentData) { |
386 | 387 | final DataSource dataSource = retrieveDataHandler(part).getDataSource(); |
387 | 388 | final String dataSourceName = parseDataSourceName(part, dataSource); |
388 | | - final String contentType = parseBaseMimeType(dataSource.getContentType()); |
389 | | - return createByteArrayDataSource(dataSource, dataSourceName, contentType, fetchAttachmentData); |
390 | | - } |
391 | | - |
392 | | - @NotNull |
393 | | - private static ByteArrayDataSource createByteArrayDataSource(DataSource dataSource, String dataSourceName, String contentType, boolean fetchAttachmentData) { |
394 | | - final InputStream is = retrieveInputStream(dataSource); |
395 | | - try { |
396 | | - final ByteArrayDataSource result = fetchAttachmentData |
397 | | - ? new ByteArrayDataSource(readContent(is), contentType) |
398 | | - : new ByteArrayDataSource(is, contentType); |
| 389 | + |
| 390 | + if (fetchAttachmentData) { |
| 391 | + final String contentType = MiscUtil.parseBaseMimeType(dataSource.getContentType()); |
| 392 | + final ByteArrayDataSource result = new ByteArrayDataSource(readContent(retrieveInputStream(dataSource)), contentType); |
399 | 393 | result.setName(dataSourceName); |
400 | 394 | return result; |
401 | | - } catch (IOException e) { |
402 | | - throw new MimeMessageParseException(MimeMessageParseException.ERROR_GETTING_INPUTSTREAM, e); |
| 395 | + } else { |
| 396 | + return new NamedDataSource(dataSourceName, dataSource); |
403 | 397 | } |
404 | 398 | } |
405 | 399 |
|
@@ -436,20 +430,6 @@ private static byte[] readContent(@NotNull final InputStream is) { |
436 | 430 | } |
437 | 431 | } |
438 | 432 |
|
439 | | - /** |
440 | | - * @param fullMimeType the mime type from the mail api |
441 | | - * @return The real mime type |
442 | | - */ |
443 | | - @NotNull |
444 | | - private static String parseBaseMimeType(@NotNull final String fullMimeType) { |
445 | | - final int pos = fullMimeType.indexOf(';'); |
446 | | - if (pos >= 0) { |
447 | | - return fullMimeType.substring(0, pos); |
448 | | - } |
449 | | - return fullMimeType; |
450 | | - } |
451 | | - |
452 | | - |
453 | 433 | @SuppressWarnings("WeakerAccess") |
454 | 434 | @NotNull |
455 | 435 | public static List<InternetAddress> parseToAddresses(@NotNull final MimeMessage mimeMessage) { |
|
0 commit comments