Skip to content

Commit

Permalink
[mail] Add action input labels and descriptions (openhab#18209)
Browse files Browse the repository at this point in the history
Signed-off-by: Jimmy Tanagra <[email protected]>
  • Loading branch information
jimtng authored Feb 1, 2025
1 parent b80efcc commit 90da7b9
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,18 @@ public class SendMailActions implements ThingActions {

@RuleAction(label = "@text/sendMessageActionLabel", description = "@text/sendMessageActionDescription")
public @ActionOutput(label = "Success", type = "java.lang.Boolean") Boolean sendMail(
@ActionInput(name = "recipient") @Nullable String recipient,
@ActionInput(name = "subject") @Nullable String subject,
@ActionInput(name = "text") @Nullable String text) {
@ActionInput(name = "recipient", label = "@text/actionInputRecipientLabel", description = "@text/actionInputRecipientDescription") @Nullable String recipient,
@ActionInput(name = "subject", label = "@text/actionInputSubjectLabel", description = "@text/actionInputSubjectDescription") @Nullable String subject,
@ActionInput(name = "text", label = "@text/actionInputTextLabel", description = "@text/actionInputTextDescription") @Nullable String text) {
return sendMailWithAttachments(recipient, subject, text, List.of());
}

@RuleAction(label = "@text/sendAttachmentMessageActionLabel", description = "@text/sendAttachmentMessageActionDescription")
public @ActionOutput(label = "Success", type = "java.lang.Boolean") Boolean sendMailWithAttachment(
@ActionInput(name = "recipient") @Nullable String recipient,
@ActionInput(name = "subject") @Nullable String subject, @ActionInput(name = "text") @Nullable String text,
@ActionInput(name = "url") @Nullable String url) {
@ActionInput(name = "recipient", label = "@text/actionInputRecipientLabel", description = "@text/actionInputRecipientDescription") @Nullable String recipient,
@ActionInput(name = "subject", label = "@text/actionInputSubjectLabel", description = "@text/actionInputSubjectDescription") @Nullable String subject,
@ActionInput(name = "text", label = "@text/actionInputTextLabel", description = "@text/actionInputTextDescription") @Nullable String text,
@ActionInput(name = "url", label = "@text/actionInputUrlLabel", description = "@text/actionInputUrlDescription") @Nullable String url) {
List<String> urlList = new ArrayList<>();
if (url != null) {
urlList.add(url);
Expand All @@ -73,9 +74,10 @@ public class SendMailActions implements ThingActions {

@RuleAction(label = "@text/sendAttachmentsMessageActionLabel", description = "@text/sendAttachmentsMessageActionDescription")
public @ActionOutput(label = "Success", type = "java.lang.Boolean") Boolean sendMailWithAttachments(
@ActionInput(name = "recipient") @Nullable String recipient,
@ActionInput(name = "subject") @Nullable String subject, @ActionInput(name = "text") @Nullable String text,
@ActionInput(name = "urlList", type = "List<String>") @Nullable List<String> urlList) {
@ActionInput(name = "recipient", label = "@text/actionInputRecipientLabel", description = "@text/actionInputRecipientDescription") @Nullable String recipient,
@ActionInput(name = "subject", label = "@text/actionInputSubjectLabel", description = "@text/actionInputSubjectDescription") @Nullable String subject,
@ActionInput(name = "text", label = "@text/actionInputTextLabel", description = "@text/actionInputTextDescription") @Nullable String text,
@ActionInput(name = "urlList", type = "List<String>", label = "@text/actionInputUrlListLabel", description = "@text/actionInputUrlListDescription") @Nullable List<String> urlList) {
if (recipient == null) {
logger.warn("Cannot send mail as recipient is missing.");
return false;
Expand Down Expand Up @@ -142,18 +144,18 @@ public static boolean sendMailWithAttachments(ThingActions actions, @Nullable St

@RuleAction(label = "@text/sendHTMLMessageActionLabel", description = "@text/sendHTMLMessageActionDescription")
public @ActionOutput(label = "Success", type = "java.lang.Boolean") Boolean sendHtmlMail(
@ActionInput(name = "recipient") @Nullable String recipient,
@ActionInput(name = "subject") @Nullable String subject,
@ActionInput(name = "htmlContent") @Nullable String htmlContent) {
@ActionInput(name = "recipient", label = "@text/actionInputRecipientLabel", description = "@text/actionInputRecipientDescription") @Nullable String recipient,
@ActionInput(name = "subject", label = "@text/actionInputSubjectLabel", description = "@text/actionInputSubjectDescription") @Nullable String subject,
@ActionInput(name = "htmlContent", label = "@text/actionInputHtmlContentLabel", description = "@text/actionInputHtmlContentDescription") @Nullable String htmlContent) {
return sendHtmlMailWithAttachments(recipient, subject, htmlContent, List.of());
}

@RuleAction(label = "@text/sendHTMLAttachmentMessageActionLabel", description = "@text/sendHTMLAttachmentMessageActionDescription")
public @ActionOutput(label = "Success", type = "java.lang.Boolean") Boolean sendHtmlMailWithAttachment(
@ActionInput(name = "recipient") @Nullable String recipient,
@ActionInput(name = "subject") @Nullable String subject,
@ActionInput(name = "htmlContent") @Nullable String htmlContent,
@ActionInput(name = "url") @Nullable String url) {
@ActionInput(name = "recipient", label = "@text/actionInputRecipientLabel", description = "@text/actionInputRecipientDescription") @Nullable String recipient,
@ActionInput(name = "subject", label = "@text/actionInputSubjectLabel", description = "@text/actionInputSubjectDescription") @Nullable String subject,
@ActionInput(name = "htmlContent", label = "@text/actionInputHtmlContentLabel", description = "@text/actionInputHtmlContentDescription") @Nullable String htmlContent,
@ActionInput(name = "url", label = "@text/actionInputUrlLabel", description = "@text/actionInputUrlDescription") @Nullable String url) {
List<String> urlList = new ArrayList<>();
if (url != null) {
urlList.add(url);
Expand All @@ -163,10 +165,10 @@ public static boolean sendMailWithAttachments(ThingActions actions, @Nullable St

@RuleAction(label = "@text/sendHTMLAttachmentsMessageActionLabel", description = "@text/sendHTMLAttachmentsMessageActionDescription")
public @ActionOutput(label = "Success", type = "java.lang.Boolean") Boolean sendHtmlMailWithAttachments(
@ActionInput(name = "recipient") @Nullable String recipient,
@ActionInput(name = "subject") @Nullable String subject,
@ActionInput(name = "htmlContent") @Nullable String htmlContent,
@ActionInput(name = "urlList", type = "List<String>") @Nullable List<String> urlList) {
@ActionInput(name = "recipient", label = "@text/actionInputRecipientLabel", description = "@text/actionInputRecipientDescription") @Nullable String recipient,
@ActionInput(name = "subject", label = "@text/actionInputSubjectLabel", description = "@text/actionInputSubjectDescription") @Nullable String subject,
@ActionInput(name = "htmlContent", label = "@text/actionInputHtmlContentLabel", description = "@text/actionInputHtmlContentDescription") @Nullable String htmlContent,
@ActionInput(name = "urlList", type = "List<String>", label = "@text/actionInputUrlListLabel", description = "@text/actionInputUrlListDescription") @Nullable List<String> urlList) {
if (recipient == null) {
logger.warn("Cannot send mail as recipient is missing.");
return false;
Expand Down Expand Up @@ -245,7 +247,8 @@ public void setThingHandler(@Nullable ThingHandler handler) {

@RuleAction(label = "@text/addHeaderActionLabel", description = "@text/addHeaderActionDescription")
public @ActionOutput(label = "Success", type = "java.lang.Boolean") Boolean addHeader(
@ActionInput(name = "name") @Nullable String name, @ActionInput(name = "value") @Nullable String value) {
@ActionInput(name = "name", label = "@text/actionInputHeaderNameLabel") @Nullable String name,
@ActionInput(name = "value", label = "@text/actionInputHeaderValueLabel") @Nullable String value) {
if (name != null && !name.isEmpty()) {
if (value != null && !value.isEmpty()) {
headers.put(name, value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,17 @@ sendHTMLMessageActionLabel = send a HTML mail
sendHTMLMessageActionDescription = Sends a HTML mail.
sendMessageActionLabel = send a text mail
sendMessageActionDescription = Sends a text mail.
actionInputRecipientLabel = Recipient
actionInputRecipientDescription = Recipient email address.
actionInputSubjectLabel = Subject
actionInputSubjectDescription = Subject of the mail.
actionInputTextLabel = Message
actionInputTextDescription = Content of the mail in text format.
actionInputUrlLabel = URL
actionInputUrlDescription = URL of the attachment.
actionInputUrlListLabel = URL List
actionInputUrlListDescription = List of URLs of the attachments.
actionInputHtmlContentLabel = HTML Message
actionInputHtmlContentDescription = Content of the mail in HTML format.
actionInputHeaderNameLabel = Header Name
actionInputHeaderValueLabel = Header Value

0 comments on commit 90da7b9

Please sign in to comment.