[
https://issues.apache.org/jira/browse/EMAIL-89?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Kevin Lester updated EMAIL-89:
------------------------------
Attachment: issue-89_patch.txt
This patch contains the following changes:
1). New "fileSize" property added to EmailAttachment
2). New "getAttachments" method added to the MultiPartEmail class.
3). New "removeAttachment" method added to the MultiPartEmail class.
4). Fixed spelling mistake in BaseEmailTestCase
5). 4 new UnitTests added to test the new functionality
Note that this patch also incorporates the patch for bug 91
Summary:
This patch updates the MultiPartEmail class to now track the EmailAttachment
objects that are attached to the email. In the "attach" method, the class now
fills in the EmailAttachment's "fileSize" attribute, and puts a reference to
the object in a LinkedHashMap. The key of the LinkedHashMap is set to the
EmailAttachment, and the value is set to the corresponding BodyPart object.
This allows the class to now return the list of original EmailAttachment
objects, as well as remove them and their corresponding BodyPart object when
the "removeAttachment" method is called.
The FileSize of an attachment is done in 1 of three ways:
1). If the attachment has its 'path' set, then the fileSize is set to the
File(path).length().
2). If the attachment has its 'url' set, then the fileSize is set to the
url.openConnection().getContentLenth().
3). If the 'attach' method is called with only a dataSource, then the fileSize
is NOT set, and is left at the default value of -1. This is because there
doesn't appear to be a safe way to get the size without affecting the
dataSource.
With this patch, users can now get the fileSize of attachments and remove them
in a manner like the following:
for (Iterator iter = email.getAttachments().iterator(); iter.hasNext();){
EmailAttachment attachment = (EmailAttachment) iter.next();
System.out.println("Attachment size = " + attachment.getFileSize() + "
bytes.");
if (attachment.getFileSize() > MAX_SIZE){
email.removeAttachment(attachment);
}
}
This patch was created against the latest code in svn, and new unit tests were
added to the MultiPartEmailTest.java for the new funcitonality. All tests pass.
> email attachment size
> ---------------------
>
> Key: EMAIL-89
> URL: https://issues.apache.org/jira/browse/EMAIL-89
> Project: Commons Email
> Issue Type: Improvement
> Reporter: yaramala
> Priority: Minor
> Attachments: issue-89_patch.txt
>
>
> Please add method to determine the size of attachment attached to email so
> that we can limit the attachments while sending via email
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.