Skip to content

Commit

Permalink
Bug 550956 - [Passage] Support mail attachment
Browse files Browse the repository at this point in the history
Rename LicensingMailDescriptor to EmailDescriptor

Signed-off-by: Alexander Fedorov <alexander.fedorov@arsysop.ru>
  • Loading branch information
ruspl-afed committed Nov 3, 2019
1 parent f678a5a commit 057ea4c
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 16 deletions.
Expand Up @@ -15,15 +15,15 @@
import java.util.ArrayList;
import java.util.List;

import org.eclipse.passage.lic.net.mail.LicensingMailDescriptor;
import org.eclipse.passage.lic.net.mail.EmailDescriptor;

/**
* The Licensing mail descriptor implementation
*
* @since 0.1.0
*
*/
public class LicensingMailDescriptorImpl implements LicensingMailDescriptor {
public class LicensingMailDescriptorImpl implements EmailDescriptor {

private final String to;
private final String from;
Expand Down
Expand Up @@ -33,7 +33,7 @@
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.passage.lic.net.mail.Mailing;
import org.eclipse.passage.lic.net.mail.LicensingMailDescriptor;
import org.eclipse.passage.lic.net.mail.EmailDescriptor;
import org.osgi.service.component.annotations.Component;

/**
Expand All @@ -48,7 +48,7 @@ public class LicensingMailImpl implements Mailing {
public static final String BUNDLE_ID = "org.eclipse.passage.lic.mail"; //$NON-NLS-1$

@Override
public void writeEml(LicensingMailDescriptor descriptor, OutputStream output,
public void writeEml(EmailDescriptor descriptor, OutputStream output,
Consumer<IStatus> consumerStatus) {
try {
Message message = createMessage(descriptor);
Expand All @@ -60,15 +60,15 @@ public void writeEml(LicensingMailDescriptor descriptor, OutputStream output,
}
}

private Message createMessage(LicensingMailDescriptor descriptor) throws MessagingException, AddressException {
private Message createMessage(EmailDescriptor descriptor) throws MessagingException, AddressException {
Message message = new MimeMessage(Session.getInstance(System.getProperties()));
message.setFrom(new InternetAddress(descriptor.getFrom()));
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(descriptor.getTo()));
message.setSubject(descriptor.getSubject());
return message;
}

private void fulfillMessage(LicensingMailDescriptor descriptor, Message message) throws MessagingException {
private void fulfillMessage(EmailDescriptor descriptor, Message message) throws MessagingException {
Multipart multipart = createBody(descriptor.getBody());
attachFiles(descriptor, multipart);
message.setContent(multipart);
Expand All @@ -82,7 +82,7 @@ private Multipart createBody(String body) throws MessagingException {
return multipart;
}

private void attachFiles(LicensingMailDescriptor descriptor, Multipart multipart) throws MessagingException {
private void attachFiles(EmailDescriptor descriptor, Multipart multipart) throws MessagingException {
Iterable<String> attachmentPaths = descriptor.getAttachmentPaths();
for (String path : attachmentPaths) {
final File attache = new File(path);
Expand All @@ -95,7 +95,7 @@ private void attachFiles(LicensingMailDescriptor descriptor, Multipart multipart
}

@Override
public LicensingMailDescriptor createMail(String to, String from, String subject, String body,
public EmailDescriptor createMail(String to, String from, String subject, String body,
Iterable<String> attachments) {
return new LicensingMailDescriptorImpl(to, from, subject, body, attachments);
}
Expand Down
Expand Up @@ -19,7 +19,7 @@
* @since 0.6
*
*/
public interface LicensingMailDescriptor {
public interface EmailDescriptor {

String getTo();

Expand Down
Expand Up @@ -25,8 +25,8 @@

public interface Mailing {

public void writeEml(LicensingMailDescriptor descriptor, OutputStream output, Consumer<IStatus> statusHandler);
public void writeEml(EmailDescriptor descriptor, OutputStream output, Consumer<IStatus> statusHandler);

public LicensingMailDescriptor createMail(String to, String from, String subject, String body,
public EmailDescriptor createMail(String to, String from, String subject, String body,
Iterable<String> attachments);
}
Expand Up @@ -26,7 +26,7 @@
import org.eclipse.passage.lic.licenses.LicenseGrantDescriptor;
import org.eclipse.passage.lic.licenses.LicensePackDescriptor;
import org.eclipse.passage.lic.net.mail.Mailing;
import org.eclipse.passage.lic.net.mail.LicensingMailDescriptor;
import org.eclipse.passage.lic.net.mail.EmailDescriptor;
import org.eclipse.passage.loc.internal.licenses.core.i18n.LicensesCoreMessages;

public class LicenseMailSupport {
Expand Down Expand Up @@ -110,7 +110,7 @@ public Optional<File> createEmlFile(File attachment) {
File emlFile = new File(System.getProperty("user.home") + File.separator + attachment + MAIL_EML_EXTENSION); //$NON-NLS-1$
try (FileOutputStream stream = new FileOutputStream(emlFile)) {
Mailing service = mailing;
LicensingMailDescriptor descriptor = service.createMail(licensePack.getUserIdentifier(), "From", //$NON-NLS-1$
EmailDescriptor descriptor = service.createMail(licensePack.getUserIdentifier(), "From", //$NON-NLS-1$
LicensesCoreMessages.LicenseRequest_mailto_subject_lbl, getDetails(MAILTO_SEPARATOR),
Collections.singleton(attachment.getPath()));

Expand Down
Expand Up @@ -36,7 +36,7 @@
import org.eclipse.core.runtime.Status;
import org.eclipse.passage.lic.internal.mail.LicensingMailImpl;
import org.eclipse.passage.lic.net.mail.Mailing;
import org.eclipse.passage.lic.net.mail.LicensingMailDescriptor;
import org.eclipse.passage.lic.net.mail.EmailDescriptor;
import org.junit.After;
import org.junit.Test;

Expand All @@ -56,7 +56,7 @@ public void shouldCreateEmlByParametersPositiveTest() {
Mailing licensingEmlService = new LicensingMailImpl();
String attachment = createAttachment();
assertFalse(attachment.isEmpty());
LicensingMailDescriptor mailDescriptor = licensingEmlService.createMail(MAIL_TO, MAIL_FROM, MAIL_SUBJECT,
EmailDescriptor mailDescriptor = licensingEmlService.createMail(MAIL_TO, MAIL_FROM, MAIL_SUBJECT,
MAIL_BODY, Collections.singleton(attachment));
assertNotNull(mailDescriptor);
try (FileOutputStream fileOutput = new FileOutputStream(MAIL_FILE_OUT)) {
Expand All @@ -73,7 +73,7 @@ public void shouldCreateEmlByParametersNagativeTest() {
Mailing licensingEmlService = new LicensingMailImpl();
String attachment = createAttachment();
assertFalse(attachment.isEmpty());
LicensingMailDescriptor mailDescriptor = licensingEmlService.createMail("", "", "", "", Collections.singleton(attachment));
EmailDescriptor mailDescriptor = licensingEmlService.createMail("", "", "", "", Collections.singleton(attachment));
assertNotNull(mailDescriptor);
try (FileOutputStream fileOutput = new FileOutputStream(MAIL_FILE_OUT)) {
IStatus errorStatus = new Status(IStatus.ERROR, this.getClass().getCanonicalName(), 1, "", null);
Expand Down

0 comments on commit 057ea4c

Please sign in to comment.