[MAGNOLIA-3597] Attach a File with MailAttachment on Windows platform Created: 29/Mar/11  Updated: 15/Aug/13  Resolved: 15/Aug/13

Status: Closed
Project: Magnolia
Component/s: None
Affects Version/s: 4.4.2
Fix Version/s: None

Type: Bug Priority: Neutral
Reporter: Vincent Gombert Assignee: Unassigned
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Windows + JDK 1.6 + Tomcat 5.5


Issue Links:
duplicate
is duplicated by MAGNOLIA-5168 MailAttachment uri may be set incorre... Closed
is duplicated by MGNLMAIL-16 MailAttachment uri may be set incorre... Closed
Template:
Acceptance criteria:
Empty
Task DoD:
[ ]* Doc/release notes changes? Comment present?
[ ]* Downstream builds green?
[ ]* Solution information and context easily available?
[ ]* Tests
[ ]* FixVersion filled and not yet released
[ ]  Architecture Decision Record (ADR)
Bug DoR:
[ ]* Steps to reproduce, expected, and actual results filled
[ ]* Affected version filled
Date of First Response:

 Description   

Using constructor info.magnolia.module.mail.templates.MailAttachment(File, String, String, String) results to an UnknownHostException while java mail is trying to get the file on Windows.
The error comes from method MailAttachment.setPath(String) which constructs a URL with file:// + absolutePath. On *nix platforms it gives us a url like file:///tmp/myfile, but on Windows the url is file://C:/temp/myfile which is wrong (root slash is missing).
I'd fix this issue by changing URL construction to :
[143] this.url = new URL(FILE_URL_PREFIX + "/" + StringUtils.removeStart(aPath, "/"));
I tested this fix on both Debian and Windows platforms.



 Comments   
Comment by Adrien Berthou [ 09/Jul/13 ]

http://forum.magnolia-cms.com/forum/thread.html?threadId=4c4ccc94-bd1a-45c3-89a2-0e8bd158ba43

Comment by Adrien Berthou [ 09/Jul/13 ]

There is a missing "/" character in MailAttachment.class

private static final String FILE_URL_PREFIX = "file://";

should be (notice the 3rd slash)

private static final String FILE_URL_PREFIX = "file:///";

Tested on windows machine

Generated at Mon Feb 12 03:47:58 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.