@@ -174,27 +174,31 @@ private void readBody(MailReader reader, MailProperties partProps, String separa
174
174
175
175
String oldSeparator = reader .getSeparator ();
176
176
reader .setSeparator (separator );
177
- OutputStream out ;
178
-
179
- if (isAttachment )
180
- {
181
- if (this .downloadAttachments ){
182
- String name = partProps .getKeyProperty (GXInternetConstants .CONTENT_TYPE , GXInternetConstants .NAME );
183
- String fileName = partProps .getKeyProperty (GXInternetConstants .CONTENT_DISPOSITION , GXInternetConstants .FILENAME );
184
- String outname = getFileName (attachmentsPath , fileName .length () == 0 ?name :fileName , partProps .getMimeMediaSubtype ());
185
-
186
- attachments += outname + ";" ;
187
- out = new FileOutputStream (attachmentsPath + outname );
177
+ OutputStream out = null ;
178
+
179
+ try {
180
+ if (isAttachment )
181
+ {
182
+ if (this .downloadAttachments ){
183
+ String name = partProps .getKeyProperty (GXInternetConstants .CONTENT_TYPE , GXInternetConstants .NAME );
184
+ String fileName = partProps .getKeyProperty (GXInternetConstants .CONTENT_DISPOSITION , GXInternetConstants .FILENAME );
185
+ String outname = getFileName (attachmentsPath , fileName .length () == 0 ?name :fileName , partProps .getMimeMediaSubtype ());
186
+
187
+ attachments += outname + ";" ;
188
+ out = new FileOutputStream (attachmentsPath + outname );
189
+ }
190
+ else
191
+ {
192
+ out = new DummyOutputStream ();
193
+ }
194
+
188
195
}
189
- else
196
+ else
190
197
{
191
- out = new DummyOutputStream ();
198
+ out = new ByteArrayOutputStream ();
192
199
}
193
-
194
- }
195
- else
196
- {
197
- out = new ByteArrayOutputStream ();
200
+ } finally {
201
+ if (out == null ) out .close ();
198
202
}
199
203
200
204
getDecoder (partProps .getField (GXInternetConstants .CONTENT_TRANSFER_ENCODING )).decode (reader , out );
0 commit comments