Skip to content
Permalink
Browse files

[mail] added dependency to javax.mail (#6494)

* added dependency to javax.mail
* added some other small fixes

Signed-off-by: Kai Kreuzer <kai@openhab.org>
  • Loading branch information
kaikreuzer authored and J-N-K committed Dec 3, 2019
1 parent 3ae6a41 commit 74d0fb337f2ad8606ebe2476ab9a49b2b50ec440
@@ -13,6 +13,7 @@
<name>openHAB Add-ons :: Bundles :: Mail Binding</name>

<properties>
<dep.noembedding>javax.mail</dep.noembedding>
<bnd.importpackage>sun.security.util;resolution:=optional</bnd.importpackage>
</properties>

@@ -4,6 +4,7 @@

<feature name="openhab-binding-mail" description="Mail Binding" version="${project.version}">
<feature>openhab-runtime-base</feature>
<bundle dependency="true">mvn:com.sun.mail/javax.mail/1.6.2</bundle>
<bundle start-level="80">mvn:org.openhab.addons.bundles/org.openhab.binding.mail/${project.version}</bundle>
</feature>
</features>
@@ -70,7 +70,7 @@
@ActionInput(name = "subject") @Nullable String subject, @ActionInput(name = "text") @Nullable String text,
@ActionInput(name = "urlList") @Nullable List<String> urlStringList) {
if (recipient == null) {
logger.info("can't send to missing recipient");
logger.warn("Cannot send mail as recipient is missing.");
return false;
}

@@ -90,19 +90,19 @@
}

if (handler == null) {
logger.info("handler is null, can't send mail");
logger.info("Handler is null, cannot send mail.");
return false;
} else {
return handler.sendMail(builder.build());
}
} catch (AddressException e) {
logger.info("could not send mail: {}", e.getMessage());
logger.warn("Could not send mail: {}", e.getMessage());
return false;
} catch (MalformedURLException e) {
logger.info("could not send mail: {}", e.getMessage());
logger.warn("Could not send mail: {}", e.getMessage());
return false;
} catch (EmailException e) {
logger.info("could not send mail: {}", e.getMessage());
logger.warn("Could not send mail: {}", e.getMessage());
return false;
}
}
@@ -126,7 +126,7 @@ public static boolean sendMail(@Nullable ThingActions actions, @Nullable String
if (actions instanceof SendMailActions) {
return ((SendMailActions) actions).sendMail(recipient, subject, text, urlStringList);
} else {
throw new IllegalArgumentException("Instance is not SendMailActions class.");
throw new IllegalArgumentException("Instance is not of class SendMailActions.");
}
}

@@ -156,7 +156,7 @@ public static boolean sendMail(@Nullable ThingActions actions, @Nullable String
@ActionInput(name = "subject") @Nullable String subject, @ActionInput(name = "html") @Nullable String html,
@ActionInput(name = "urlList") @Nullable List<String> urlStringList) {
if (recipient == null) {
logger.info("can't send to missing recipient");
logger.warn("Cannot send mail as recipient is missing.");
return false;
}

@@ -176,19 +176,19 @@ public static boolean sendMail(@Nullable ThingActions actions, @Nullable String
}

if (handler == null) {
logger.info("handler is null, can't send mail");
logger.warn("Handler is null, cannot send mail.");
return false;
} else {
return handler.sendMail(builder.build());
}
} catch (AddressException e) {
logger.info("could not send mail: {}", e.getMessage());
logger.warn("Could not send mail: {}", e.getMessage());
return false;
} catch (MalformedURLException e) {
logger.info("could not send mail: {}", e.getMessage());
logger.warn("Could not send mail: {}", e.getMessage());
return false;
} catch (EmailException e) {
logger.info("could not send mail: {}", e.getMessage());
logger.warn("could not send mail: {}", e.getMessage());
return false;
}
}
@@ -198,7 +198,7 @@ public static boolean sendHtmlMail(@Nullable ThingActions actions, @Nullable Str
return SendMailActions.sendHtmlMail(actions, recipient, subject, html, new ArrayList<String>());
}

public static boolean sendHtmMail(@Nullable ThingActions actions, @Nullable String recipient,
public static boolean sendHtmlMail(@Nullable ThingActions actions, @Nullable String recipient,
@Nullable String subject, @Nullable String html, @Nullable String urlString) {
List<String> urlList = new ArrayList<>();
if (urlString != null) {
@@ -212,7 +212,7 @@ public static boolean sendHtmlMail(@Nullable ThingActions actions, @Nullable Str
if (actions instanceof SendMailActions) {
return ((SendMailActions) actions).sendHtmlMail(recipient, subject, html, urlStringList);
} else {
throw new IllegalArgumentException("Instance is not SendMailActions class.");
throw new IllegalArgumentException("Instance is not of class SendMailActions.");
}
}

@@ -164,10 +164,8 @@ public Email build() throws EmailException {
multipartMail.attach(file);
}
for (URL url : attachmentURLs) {
EmailAttachment attachment = new EmailAttachment();
attachment.setURL(url);
attachment.setDisposition(EmailAttachment.ATTACHMENT);
multipartMail.attach(attachment);
String fileName = url.toString().replaceFirst(".*/([^/?]+).*", "$1");
multipartMail.attach(url, fileName, fileName, EmailAttachment.ATTACHMENT);
}
mail = multipartMail;
} else {

0 comments on commit 74d0fb3

Please sign in to comment.
You can’t perform that action at this time.