use of org.eclipse.scout.rt.platform.resource.BinaryResource in project scout.rt by eclipse.
the class MalwareScannerTest method testEmptyContent.
@Test
public void testEmptyContent() {
BinaryResource res = new BinaryResource("safe-test.txt", new byte[0]);
new MalwareScanner().scan(res);
}
use of org.eclipse.scout.rt.platform.resource.BinaryResource in project scout.rt by eclipse.
the class MalwareScannerTest method testSafeContent.
@Test
public void testSafeContent() {
BinaryResource res = new BinaryResource("safe-test.txt", SAFE_CONTENT.getBytes());
new MalwareScanner().scan(res);
}
use of org.eclipse.scout.rt.platform.resource.BinaryResource in project scout.rt by eclipse.
the class MalwareScannerTest method testEicarVirus.
@Ignore("Typically there is no on-site malware scanner on xnix-based systems")
@Test
public void testEicarVirus() {
thrown.expect(PlatformException.class);
thrown.expectMessage("Resource 'virus-test.txt' is not safe");
BinaryResource res = new BinaryResource("virus-test.txt", EICAR_TEST_VIRUS.getBytes());
new MalwareScanner().scan(res);
}
use of org.eclipse.scout.rt.platform.resource.BinaryResource in project scout.rt by eclipse.
the class MalwareScannerTest method testNullContent.
@Test
public void testNullContent() {
BinaryResource res = new BinaryResource("safe-test.txt", null);
new MalwareScanner().scan(res);
}
use of org.eclipse.scout.rt.platform.resource.BinaryResource in project scout.rt by eclipse.
the class MailHelper method addResourcesAsAttachments.
/**
* Adds the provided attachments to the existing mime message.
* <p>
* When working with {@link File}, use {@link #addAttachmentsToMimeMessage(MimeMessage, List)} instead.
*
* @param msg
* Mime message to attach files to
* @param attachments
* List of attachments (binary resources).
* @since 6.0
*/
public void addResourcesAsAttachments(MimeMessage msg, List<BinaryResource> attachments) {
if (CollectionUtility.isEmpty(attachments)) {
return;
}
try {
Multipart multiPart = prepareMessageForAttachments(msg);
for (BinaryResource attachment : attachments) {
MimeBodyPart bodyPart = new MimeBodyPart();
DataSource source = new BinaryResourceDataSource(attachment);
bodyPart.setDataHandler(new DataHandler(source));
bodyPart.setFileName(MimeUtility.encodeText(attachment.getFilename(), "UTF-8", null));
multiPart.addBodyPart(bodyPart);
}
msg.saveChanges();
} catch (MessagingException e) {
throw new ProcessingException("Failed to add attachment to existing mime message", e);
} catch (IOException e) {
throw new ProcessingException("Failed to add attachment to existing mime message", e);
}
}
Aggregations