Skip to content
This repository was archived by the owner on Aug 20, 2025. It is now read-only.

Commit 840c567

Browse files
committed
Merge branch 'fred84-imap_attachement_filename_fix'
2 parents 1ccd6b4 + 2227272 commit 840c567

3 files changed

Lines changed: 29 additions & 1 deletion

File tree

doc/release/CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ GH 321 URLName.getURL() returns incorrect url.
3131
GH 322 Dots in local part of emails not handled properly
3232
GH 323 Support loading protocol providers using ServiceLoader
3333
GH 326 Apply relaxed Content-Disposition parsing to Content-Disposition params
34+
GH 330 Attachment filename is ignored
3435
GH 332 http proxy support should support authenticating to the proxy server
3536

3637

mail/src/main/java/com/sun/mail/imap/IMAPBodyPart.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ public String getFileName() throws MessagingException {
168168
String filename = null;
169169
if (bs.dParams != null)
170170
filename = bs.dParams.get("filename");
171-
if (filename == null && bs.cParams != null)
171+
if ((filename == null || filename.isEmpty()) && bs.cParams != null)
172172
filename = bs.cParams.get("name");
173173
if (decodeFileName && filename != null) {
174174
try {

mail/src/test/java/com/sun/mail/imap/IMAPMessageTest.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,33 @@ else if (line.indexOf("BODY[TEXT]") >= 0)
178178
});
179179
}
180180

181+
@Test
182+
public void testAttachementFileName() {
183+
testWithHandler(
184+
new IMAPTest() {
185+
@Override
186+
public void test(Folder folder, IMAPHandlerMessage handler) throws MessagingException, IOException {
187+
Message m = folder.getMessage(1);
188+
Multipart mp = (Multipart)m.getContent();
189+
BodyPart bp = mp.getBodyPart(1);
190+
assertEquals("filename.csv", MimeUtility.decodeText(bp.getFileName()));
191+
}
192+
},
193+
new IMAPHandlerMessage() {
194+
@Override
195+
public void fetch(String line) throws IOException {
196+
untagged("1 FETCH (BODYSTRUCTURE (" +
197+
"(\"text\" \"html\" (\"charset\" \"utf-8\") NIL NIL \"base64\" 402 6 NIL NIL NIL NIL)" +
198+
"(\"application\" \"octet-stream\" (\"name\" \"=?utf-8?B?ZmlsZW5hbWU=?= =?utf-8?B?LmNzdg==?=\") NIL NIL \"base64\" 658 NIL " +
199+
"(\"attachment\" (\"filename\" \"\")) NIL NIL) \"mixed\" " +
200+
"(\"boundary\" \"--boundary_539_27806e16-2599-4612-b98a-69335bedd206\") NIL NIL NIL))"
201+
);
202+
ok();
203+
}
204+
}
205+
);
206+
}
207+
181208
/**
182209
* Test that returning NIL instead of an empty string for the content
183210
* of an empty body part works correctly.

0 commit comments

Comments
 (0)