This repository was archived by the owner on Aug 20, 2025. It is now read-only.
File tree Expand file tree Collapse file tree
main/java/com/sun/mail/imap
test/java/com/sun/mail/imap Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -31,6 +31,7 @@ GH 321 URLName.getURL() returns incorrect url.
3131GH 322 Dots in local part of emails not handled properly
3232GH 323 Support loading protocol providers using ServiceLoader
3333GH 326 Apply relaxed Content-Disposition parsing to Content-Disposition params
34+ GH 330 Attachment filename is ignored
3435GH 332 http proxy support should support authenticating to the proxy server
3536
3637
Original file line number Diff line number Diff 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 {
Original file line number Diff line number Diff 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.
You can’t perform that action at this time.
0 commit comments