From 89452918e15a5c7ee99c89d4ad4880a88b2c514a Mon Sep 17 00:00:00 2001 From: J-N-K Date: Sat, 15 Jul 2023 10:26:59 +0200 Subject: [PATCH] [mail] remove binding (#502) Signed-off-by: Jan N. Klug --- bundles/org.smarthomej.binding.mail/NOTICE | 27 -- bundles/org.smarthomej.binding.mail/README.md | 164 ------- bundles/org.smarthomej.binding.mail/pom.xml | 64 --- .../activation/PatchedMailcapCommandMap.java | 433 ------------------ .../src/main/feature/feature.xml | 10 - .../mail/internal/MailBindingConstants.java | 43 -- .../binding/mail/internal/MailBuilder.java | 220 --------- .../mail/internal/MailCountChannelType.java | 27 -- .../mail/internal/MailHandlerFactory.java | 64 --- .../mail/internal/POP3IMAPHandler.java | 220 --------- .../binding/mail/internal/SMTPHandler.java | 144 ------ .../binding/mail/internal/ServerSecurity.java | 28 -- .../mail/internal/action/SendMailActions.java | 281 ------------ .../mail/internal/config/BaseConfig.java | 33 -- .../mail/internal/config/POP3IMAPConfig.java | 27 -- .../config/POP3IMAPContentChannelConfig.java | 33 -- .../POP3IMAPMailCountChannelConfig.java | 30 -- .../mail/internal/config/SMTPConfig.java | 28 -- .../src/main/resources/OH-INF/addon/addon.xml | 10 - .../resources/OH-INF/i18n/mail.properties | 24 - .../resources/OH-INF/i18n/mail_de.properties | 95 ---- .../resources/OH-INF/thing/thing-types.xml | 163 ------- .../binding/mail/MailBuilderTest.java | 101 ---- bundles/pom.xml | 1 - 24 files changed, 2270 deletions(-) delete mode 100644 bundles/org.smarthomej.binding.mail/NOTICE delete mode 100644 bundles/org.smarthomej.binding.mail/README.md delete mode 100644 bundles/org.smarthomej.binding.mail/pom.xml delete mode 100644 bundles/org.smarthomej.binding.mail/src/3rdparty/java/javax/activation/PatchedMailcapCommandMap.java delete mode 100644 bundles/org.smarthomej.binding.mail/src/main/feature/feature.xml delete mode 100644 bundles/org.smarthomej.binding.mail/src/main/java/org/smarthomej/binding/mail/internal/MailBindingConstants.java delete mode 100644 bundles/org.smarthomej.binding.mail/src/main/java/org/smarthomej/binding/mail/internal/MailBuilder.java delete mode 100644 bundles/org.smarthomej.binding.mail/src/main/java/org/smarthomej/binding/mail/internal/MailCountChannelType.java delete mode 100644 bundles/org.smarthomej.binding.mail/src/main/java/org/smarthomej/binding/mail/internal/MailHandlerFactory.java delete mode 100644 bundles/org.smarthomej.binding.mail/src/main/java/org/smarthomej/binding/mail/internal/POP3IMAPHandler.java delete mode 100644 bundles/org.smarthomej.binding.mail/src/main/java/org/smarthomej/binding/mail/internal/SMTPHandler.java delete mode 100644 bundles/org.smarthomej.binding.mail/src/main/java/org/smarthomej/binding/mail/internal/ServerSecurity.java delete mode 100644 bundles/org.smarthomej.binding.mail/src/main/java/org/smarthomej/binding/mail/internal/action/SendMailActions.java delete mode 100644 bundles/org.smarthomej.binding.mail/src/main/java/org/smarthomej/binding/mail/internal/config/BaseConfig.java delete mode 100644 bundles/org.smarthomej.binding.mail/src/main/java/org/smarthomej/binding/mail/internal/config/POP3IMAPConfig.java delete mode 100644 bundles/org.smarthomej.binding.mail/src/main/java/org/smarthomej/binding/mail/internal/config/POP3IMAPContentChannelConfig.java delete mode 100644 bundles/org.smarthomej.binding.mail/src/main/java/org/smarthomej/binding/mail/internal/config/POP3IMAPMailCountChannelConfig.java delete mode 100644 bundles/org.smarthomej.binding.mail/src/main/java/org/smarthomej/binding/mail/internal/config/SMTPConfig.java delete mode 100644 bundles/org.smarthomej.binding.mail/src/main/resources/OH-INF/addon/addon.xml delete mode 100644 bundles/org.smarthomej.binding.mail/src/main/resources/OH-INF/i18n/mail.properties delete mode 100644 bundles/org.smarthomej.binding.mail/src/main/resources/OH-INF/i18n/mail_de.properties delete mode 100644 bundles/org.smarthomej.binding.mail/src/main/resources/OH-INF/thing/thing-types.xml delete mode 100644 bundles/org.smarthomej.binding.mail/src/test/java/org/smarthomej/binding/mail/MailBuilderTest.java diff --git a/bundles/org.smarthomej.binding.mail/NOTICE b/bundles/org.smarthomej.binding.mail/NOTICE deleted file mode 100644 index 38145258a2..0000000000 --- a/bundles/org.smarthomej.binding.mail/NOTICE +++ /dev/null @@ -1,27 +0,0 @@ -This content is produced and maintained by the SmartHome/J project. - -* Project home: https://www.smarthomej.org - -== Declared Project Licenses - -This program and the accompanying materials are made available under the terms -of the Eclipse Public License 2.0 which is available at -https://www.eclipse.org/legal/epl-2.0/. - -== Source Code - -https://github.com/smarthomej/addons - -Parts of this code have been forked from https://github.com/openhab/openhab-addons - -== Third-party Content - -commons-email: -* License: Apache 2.0 License -* Project: https://commons.apache.org/proper/commons-email -* Source: https://commons.apache.org/proper/commons-email - -javax.mail: -* License: Common Development and Distribution License (CDDL) v1.1 and GNU General Public License (GPL) v2 with Classpath Exception -* Project: https://javaee.github.io/javamail/ -* Source: https://github.com/javaee/javamail diff --git a/bundles/org.smarthomej.binding.mail/README.md b/bundles/org.smarthomej.binding.mail/README.md deleted file mode 100644 index 393d307c89..0000000000 --- a/bundles/org.smarthomej.binding.mail/README.md +++ /dev/null @@ -1,164 +0,0 @@ -# Mail Binding - -The Mail binding provides support for sending mails from rules. - -***Deprecation warning:*** The action methods `sendMail(...)` and `sendHtmlMail(...)` for sending mails with attachments are deprecated. -Use `sendMailWithAttachment/sendMailWithAttachments` (or respective methods for HTML mails, see below). - -## Supported Things - -There are three things: `smtp`, `imap` and `pop3` which represents respective servers. - -## Thing Configuration - -### SMTP Server (`smtp`) - -There are two mandatory parameters `hostname` and `sender`. - -The `hostname` may contain an IP address or a FQDN like `smtp.gmail.com`. -The `sender` must be a valid mail address used as sender address for mails. - -The `security`, `port`, `username` and `password` parameters are optional. - -The `security` parameter defines the transport security and can be set to `PLAIN` (default), `STARTTLS` or `SSL` (for implicit SSL/TLS). -The `port` parameter is used to change the default ports for the SMTP server. -Default ports are `25` (for `PLAIN` and `STARTTLS`) and `465` (for `SSL`). -For authentication, `username` and `password` can be supplied. -If one or both are empty, no authentication data is provided to the SMTP server during connect. - -### IMAP Server (`imap`) / POP3 Server (`pop3`) - -There is one mandatory parameter: `hostname`. -The `hostname` may contain an IP address or a FQDN like `mail.gmail.com`. -For authentication `username` and `password` also need to be supplied. - -The `refresh`, `security`, `port`, `username` and `password` parameters are optional. - -The `refresh` parameter is the time in seconds between two refreshes of the thing's channels. -If omitted, the default of 60s is used. -The `security` parameter defines the transport security and can be set to `PLAIN` (default), `STARTTLS` or `SSL` (for implicit SSL/TLS). -The `port` parameter is used to change the default ports for the SMTP server. -Default ports are `143` (for `PLAIN` and `STARTTLS`) and `993` (for `SSL`) in the case of `imap` or `110` (for `PLAIN` and `STARTTLS`) and `995` (for `SSL`) in the case of `pop3`. - -## Channels - -There are no channels for the `smtp` thing. -The `imap` and `pop3` things can be extended with `mailcount`- and `content`-type channels. - -### Type `mailcount` - -Each channel has two parameters: `folder` and `type`. - -The `folder` is mandatory and denotes the folder name on the given account. -You can either use the root folder like (e.g. "INBOX") or a sub directory of your structure (e.g. "INBOX.Sent" or "INBOX.Junk"). - -The `type` parameter can be `UNREAD` or `TOTAL` (default). -Channels with type `UNREAD` give the number on unread mails in that folder. - -### Type `content` - -The `content` type channel presents the contents of an unread mail. -If the message is a MIME- or MIME-multipart message, all parts are concatenated. -The content is converted to a plain string without processing (i.e. HTML tags are still present). -In most cases the mail content needs further processing in rules to trigger appropriate action. - -Each channel has five parameters: `folder`, `subject`, `sender`, `transformation` and `markAsRead`. - -The `folder` is mandatory and denotes the folder name on the given account. -You can either use the root folder like (e.g. "INBOX") or a sub directory of your structure (e.g. "INBOX.Sent" or "INBOX.Junk"). - -`subject` and `sender` can be used to filter the messages that are processed by the channel. -Filters use regular expressions (e.g. `.*DHL.*` as `sender` would match all From-addresses that contain "DHL"). -If a parameter is left empty, no filter is applied. - -The `transformation` is applied before setting the channel status. -Transformations can be chained by separating them with the mathematical intersection character "∩", e.g. `REGEX:.*Shipment-Status: ([a-z]+).*∩MAP:status.map` would first extract a character string with a regular expression and then apply the given MAP transformation on the result. -Please note that the values will be discarded if one transformation fails (e.g. REGEX did not match). -This means that you can also use it to filter certain emails e.g. `REGEX:(.*Sendungsbenachrichtigung.*)` would only match for mails containing the string "Sendungsbenachrichtigung" but output the whole message. - -Since with each refresh all unread mails are processed the same message content would be sent to the channel multiple times. -This can be prevented by setting `markAsRead` to `true` (default is `false`), which marks all processed messages as read. - -## Full Example - -mail.things: - -``` -Thing mail:smtp:samplesmtp [ hostname="smtp.example.com", sender="mail@example.com", security="SSL", username="user", password="pass" ] - -Thing mail:imap:sampleimap [ hostname="imap.example.com", security="SSL", username="user", password="pass" ] { - Channels: - Type mailcount : inbox_total [ folder="INBOX", type="TOTAL" ] - Type mailcount : inbox_unread [ folder="INBOX", type="UNREAD" ] - Type content : fedex_notification [ folder="INBOX" sender="Fedex.*" markAsRead="true" ] -} -``` - -mail.items: - -``` -Number InboxTotal "INBOX [%d]" { channel="mail:imap:sampleimap:inbox_total" } -Number InboxUnread "INBOX Unread [%d]" { channel="mail:imap:sampleimap:inbox_unread" } -String FedexNotification { channel="mail:imap:sampleimap:fedex_notification" } -``` - -mail.sitemap: - -``` -sitemap demo label="Main Menu" -{ - Frame { - Text item=InboxTotal - Text item=InboxUnread - } -} -``` - -## Rule Action - -This binding includes rule actions for sending email. -Six different actions available: - -* `boolean success = sendMail(String recipient, String subject, String text)` -* `boolean success = sendMailWithAttachment(String recipient, String subject, String text, String URL)` -* `boolean success = sendMailWithAttachments(String recipient, String subject, String text, List URL)` -* `boolean success = sendComplexMail(String recipient, String subject, String text, List URL, Map headers)` -* `boolean success = sendHtmlMail(String recipient, String subject, String htmlContent)` -* `boolean success = sendHtmlMailWithAttachment(String recipient, String subject, String htmlContent, String URL)` -* `boolean success = sendHtmlMailWithAttachments(String recipient, String subject, String htmlContent, List URL)` -* `boolean success = sendHtmlMailWithAttachments(String recipient, String subject, String htmlContent, List URL, Map headers)` - -The `sendMail...(...)` actions send a plain text mail. -The `sendHtmlMail...(...)` actions send an HTML mail. - -All methods return a boolean as the result of the operation. - -`recipient` can be a single address (`mail@example.com`) or a list of addresses, concatenated by a comma (`mail@example.com, mail2@example.com`). - -The `sendComplexMail` and `sendComplexHtmlMail` methods allow `null` values for all parameters except the `recipient`. - -Since there is a separate rule action instance for each `smtp` thing, this needs to be retrieved through `getActions(scope, thingUID)`. -The first parameter always has to be `mail` and the second is the full Thing UID of the SMTP server that should be used. -Once this action instance is retrieved, you can invoke the action method on it. - -Please note: All strings are expected to be UTF-8 encoded. -Using different character sets may produce unwanted results. - -Examples (Rules DSL): - -``` -val mailActions = getActions("mail","mail:smtp:samplesmtp") -val success = mailActions.sendMail("mail@example.com", "Test subject", "This is the mail content.") -success = mailActions.sendMail("mail1@example.com, mail2@example.com", "Test subject", "This is the mail content sent to multiple recipients.") - -``` - -``` -import java.util.List - -val List attachmentUrlList = new ArrayList( - "http://some.web/site/snap.jpg¶m=value", - "file:///tmp/201601011031.jpg") -val mailActions = getActions("mail","mail:smtp:sampleserver") -mailActions.sendHtmlMailWithAttachments("mail@example.com", "Test subject", "

Header

This is the mail content.", attachmentUrlList) -``` diff --git a/bundles/org.smarthomej.binding.mail/pom.xml b/bundles/org.smarthomej.binding.mail/pom.xml deleted file mode 100644 index c0b36a888b..0000000000 --- a/bundles/org.smarthomej.binding.mail/pom.xml +++ /dev/null @@ -1,64 +0,0 @@ - - - 4.0.0 - - - org.smarthomej.addons.bundles - org.smarthomej.addons.reactor.bundles - 4.0.0-SNAPSHOT - - - org.smarthomej.binding.mail - - SmartHome/J Add-ons :: Bundles :: Mail Binding - - - javax.mail - sun.security.util;resolution:=optional - - - - - org.apache.commons - commons-email - 1.5 - compile - - - com.sun.mail - javax.mail - 1.6.2 - compile - - - org.smarthomej.addons.bundles - org.smarthomej.commons - ${project.version} - provided - - - - - - - org.codehaus.mojo - build-helper-maven-plugin - - - - add-source - - generate-sources - - - src/3rdparty/java - - - - - - - - - diff --git a/bundles/org.smarthomej.binding.mail/src/3rdparty/java/javax/activation/PatchedMailcapCommandMap.java b/bundles/org.smarthomej.binding.mail/src/3rdparty/java/javax/activation/PatchedMailcapCommandMap.java deleted file mode 100644 index 9b2f2041cd..0000000000 --- a/bundles/org.smarthomej.binding.mail/src/3rdparty/java/javax/activation/PatchedMailcapCommandMap.java +++ /dev/null @@ -1,433 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package javax.activation; - -import javax.mail.Session; -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.Reader; -import java.lang.reflect.InvocationTargetException; -import java.net.URL; -import java.util.ArrayList; -import java.util.Enumeration; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; - -/** - * @version $Rev$ $Date$ - * - * Changelog: - * - typed collections - * - use javax.mail.Session classloader instead of context classloader - * - remove unused constructors - * - code-style improvements - * - */ -public class PatchedMailcapCommandMap extends CommandMap { - /** - * A string that holds all the special chars. - */ - private static final String TSPECIALS = "()<>@,;:/[]?=\\\""; - private final Map mimeTypes = new HashMap<>(); - private final Map> preferredCommands = new HashMap<>(); - private final Map> allCommands = new HashMap<>(); - // the unparsed commands from the mailcap file. - private final Map> nativeCommands = new HashMap<>(); - // commands identified as fallbacks...these are used last, and also used as wildcards. - private final Map> fallbackCommands = new HashMap<>(); - - public PatchedMailcapCommandMap() { - ClassLoader contextLoader = Objects.requireNonNull(Session.class.getClassLoader()); - // process /META-INF/mailcap resources - try { - Enumeration e = contextLoader.getResources("META-INF/mailcap"); - while (e.hasMoreElements()) { - URL url = e.nextElement(); - try (InputStream is = url.openStream()) { - parseMailcap(is); - } catch (IOException ignored) { - } - } - } catch (SecurityException | IOException e) { - // ignore - } - } - - private void parseMailcap(InputStream is) { - try { - parseMailcap(new InputStreamReader(is)); - } catch (IOException e) { - // spec API means all we can do is swallow this - } - } - - void parseMailcap(Reader reader) throws IOException { - BufferedReader br = new BufferedReader(reader); - String line; - while ((line = br.readLine()) != null) { - addMailcap(line); - } - } - - public synchronized void addMailcap(String mail_cap) { - int index = 0; - // skip leading whitespace - index = skipSpace(mail_cap, index); - if (index == mail_cap.length() || mail_cap.charAt(index) == '#') { - return; - } - - // get primary type - int start = index; - index = getToken(mail_cap, index); - if (start == index) { - return; - } - String mimeType = mail_cap.substring(start, index); - - // skip any spaces after the primary type - index = skipSpace(mail_cap, index); - if (index == mail_cap.length() || mail_cap.charAt(index) == '#') { - return; - } - - // get sub-type - if (mail_cap.charAt(index) == '/') { - index = skipSpace(mail_cap, ++index); - start = index; - index = getToken(mail_cap, index); - mimeType = mimeType + '/' + mail_cap.substring(start, index); - } else { - - mimeType = mimeType + "/*"; - } - - // we record all mappings using the lowercase version. - mimeType = mimeType.toLowerCase(); - - // skip spaces after mime type - index = skipSpace(mail_cap, index); - - // expect a ';' to terminate field 1 - if (index == mail_cap.length() || mail_cap.charAt(index) != ';') { - return; - } - // ok, we've parsed the mime text field, now parse the view field. If there's something - // there, then we add this to the native text. - index = skipSpace(mail_cap, index + 1); - // if the next encountered text is not a ";", then we have a view. This gets added to the - // native list. - if (index == mail_cap.length() || mail_cap.charAt(index) != ';') { - List nativeCommandList = Objects.requireNonNull(nativeCommands.computeIfAbsent(mimeType, k -> new ArrayList<>())); - // now add this as an entry in the list. - nativeCommandList.add(mail_cap); - // now skip forward to the next field marker, if any - index = getMText(mail_cap, index); - } - - // we don't know which list this will be added to until we finish parsing, as there - // can be an x-java-fallback-entry parameter that moves this to the fallback list. - List commandList = new ArrayList<>(); - // but by default, this is not a fallback. - boolean fallback = false; - - // parse fields - while (index < mail_cap.length() && mail_cap.charAt(index) == ';') { - index = skipSpace(mail_cap, index + 1); - start = index; - index = getToken(mail_cap, index); - String fieldName = mail_cap.substring(start, index).toLowerCase(); - index = skipSpace(mail_cap, index); - if (index < mail_cap.length() && mail_cap.charAt(index) == '=') { - index = skipSpace(mail_cap, index + 1); - start = index; - index = getMText(mail_cap, index); - String value = mail_cap.substring(start, index); - index = skipSpace(mail_cap, index); - if (fieldName.startsWith("x-java-") && fieldName.length() > 7) { - String command = fieldName.substring(7); - value = value.trim(); - if (command.equals("fallback-entry")) { - if (value.equals("true")) { - fallback = true; - } - } - else { - // create a CommandInfo item and add it the accumulator - CommandInfo info = new CommandInfo(command, value); - commandList.add(info); - } - } - } - } - addCommands(mimeType, commandList, fallback); - } - - /** - * Add a parsed list of commands to the appropriate command list. - * - * @param mimeType The mimeType name this is added under. - * @param commands A List containing the command information. - * @param fallback The target list identifier. - */ - protected void addCommands(String mimeType, List commands, boolean fallback) { - // add this to the mimeType set - mimeTypes.put(mimeType, mimeType); - // the target list changes based on the type of entry. - Map> target = fallback ? fallbackCommands : preferredCommands; - - // now process - for (CommandInfo info : commands) { - addCommand(target, mimeType, info); - // if this is not a fallback position, then this to the allcommands list. - if (!fallback) { - List cmdList = allCommands.computeIfAbsent(mimeType, k -> new ArrayList<>()); - addUnique(cmdList, info); - } - } - } - - private void addUnique(List commands, CommandInfo newCommand) { - for (CommandInfo info : commands) { - if (info.getCommandName().equals(newCommand.getCommandName()) && info.getCommandClass() - .equals(newCommand.getCommandClass())) { - return; - } - } - commands.add(newCommand); - } - - /** - * Add a command to a target command list (preferred or fallback). - * - * @param commandList - * The target command list. - * @param mimeType The MIME type the command is associated with. - * @param command The command information. - */ - protected void addCommand(Map> commandList, String mimeType, CommandInfo command) { - Map commands = Objects.requireNonNull(commandList.computeIfAbsent(mimeType, k -> new HashMap<>())); - commands.put(command.getCommandName(), command); - } - - - private int skipSpace(String s, int index) { - while (index < s.length() && Character.isWhitespace(s.charAt(index))) { - index++; - } - return index; - } - - private int getToken(String s, int index) { - while (index < s.length() && s.charAt(index) != '#' && !isSpecialCharacter(s.charAt(index))) { - index++; - } - return index; - } - - private int getMText(String s, int index) { - while (index < s.length()) { - char c = s.charAt(index); - if (c == '#' || c == ';' || Character.isISOControl(c)) { - return index; - } - if (c == '\\') { - index++; - if (index == s.length()) { - return index; - } - } - index++; - } - return index; - } - - public synchronized CommandInfo[] getPreferredCommands(String mimeType) { - // get the mimetype as a lowercase version. - mimeType = mimeType.toLowerCase(); - - Map commands = preferredCommands.get(mimeType); - if (commands == null) { - commands = preferredCommands.get(getWildcardMimeType(mimeType)); - } - - Map fallbackCommands = getFallbackCommands(mimeType); - - // if we have fall backs, then we need to merge this stuff. - if (fallbackCommands != null) { - // if there's no command list, we can just use this as the master list. - if (commands == null) { - commands = fallbackCommands; - } - else { - // merge the two lists. The ones in the commands list will take precedence. - commands = mergeCommandMaps(commands, fallbackCommands); - } - } - - // now convert this into an array result. - if (commands == null) { - return new CommandInfo[0]; - } - return commands.values().toArray(new CommandInfo[0]); - } - - private Map getFallbackCommands(String mimeType) { - Map commands = fallbackCommands.get(mimeType); - - // now we also need to search this as if it was a wildcard. If we get a wildcard hit, - // we have to merge the two lists. - Map wildcardCommands = fallbackCommands.get(getWildcardMimeType(mimeType)); - // no wildcard version - if (wildcardCommands == null) { - return commands; - } - // we need to merge these. - return mergeCommandMaps(commands, wildcardCommands); - } - - - private Map mergeCommandMaps(Map main, Map fallback) { - // create a cloned copy of the second map. We're going to use a PutAll operation to - // overwrite any duplicates. - Map result = new HashMap<>(fallback); - result.putAll(main); - - return result; - } - - public synchronized CommandInfo[] getAllCommands(String mimeType) { - mimeType = mimeType.toLowerCase(); - List exactCommands = allCommands.get(mimeType); - if (exactCommands == null) { - exactCommands = List.of(); - } - List wildCommands = allCommands.get(getWildcardMimeType(mimeType)); - if (wildCommands == null) { - wildCommands = List.of(); - } - - Map fallbackCommands = getFallbackCommands(mimeType); - if (fallbackCommands == null) { - fallbackCommands = Map.of(); - } - - - CommandInfo[] result = new CommandInfo[exactCommands.size() + wildCommands.size() + fallbackCommands.size()]; - int j = 0; - for (CommandInfo exactCommand : exactCommands) { - result[j++] = exactCommand; - } - for (CommandInfo wildCommand : wildCommands) { - result[j++] = wildCommand; - } - - for (String s : fallbackCommands.keySet()) { - result[j++] = fallbackCommands.get(s); - } - return result; - } - - public synchronized CommandInfo getCommand(String mimeType, String cmdName) { - mimeType = mimeType.toLowerCase(); - // strip any parameters from the supplied mimeType - int i = mimeType.indexOf(';'); - if (i != -1) { - mimeType = mimeType.substring(0, i).trim(); - } - cmdName = cmdName.toLowerCase(); - - // search for an exact match - Map commands = preferredCommands.get(mimeType); - if (commands == null || commands.get(cmdName) == null) { - // then a wild card match - commands = preferredCommands.get(getWildcardMimeType(mimeType)); - if (commands == null || commands.get(cmdName) == null) { - // then fallback searches, both standard and wild card. - commands = fallbackCommands.get(mimeType); - if (commands == null || commands.get(cmdName) == null) { - commands = fallbackCommands.get(getWildcardMimeType(mimeType)); - } - if (commands == null) { - return null; - } - } - } - return commands.get(cmdName); - } - - private String getWildcardMimeType(String mimeType) { - int i = mimeType.indexOf('/'); - if (i == -1) { - return mimeType + "/*"; - } else { - return mimeType.substring(0, i + 1) + "*"; - } - } - - public synchronized DataContentHandler createDataContentHandler(String mimeType) { - CommandInfo info = getCommand(mimeType, "content-handler"); - if (info == null) { - return null; - } - - ClassLoader cl = Objects.requireNonNull(Session.class.getClassLoader()); - try { - return (DataContentHandler) cl.loadClass(info.getCommandClass()).getDeclaredConstructor().newInstance(); - } catch (ClassNotFoundException | IllegalAccessException | InstantiationException | NoSuchMethodException | InvocationTargetException e) { - return null; - } - } - - /** - * Get all MIME types known to this command map. - * - * @return A String array of the MIME type names. - */ - public synchronized String[] getMimeTypes() { - List types = new ArrayList<>(mimeTypes.values()); - return types.toArray(new String[0]); - } - - /** - * Return the list of raw command strings parsed - * from the mailcap files for a given mimeType. - * - * @param mimeType The target mime type - * - * @return A String array of the raw command strings. Returns - * an empty array if the mimetype is not currently known. - */ - public synchronized String[] getNativeCommands(String mimeType) { - List commands = nativeCommands.get(mimeType.toLowerCase()); - if (commands == null) { - return new String[0]; - } - return commands.toArray(new String[0]); - } - - private boolean isSpecialCharacter(char c) { - return Character.isWhitespace(c) || Character.isISOControl(c) || TSPECIALS.indexOf(c) != -1; - } -} \ No newline at end of file diff --git a/bundles/org.smarthomej.binding.mail/src/main/feature/feature.xml b/bundles/org.smarthomej.binding.mail/src/main/feature/feature.xml deleted file mode 100644 index fb60c70d98..0000000000 --- a/bundles/org.smarthomej.binding.mail/src/main/feature/feature.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - openhab-runtime-base - mvn:com.sun.mail/javax.mail/1.6.2 - mvn:org.apache.servicemix.specs/org.apache.servicemix.specs.activation-api-1.1/2.9.0 - mvn:org.smarthomej.addons.bundles/org.smarthomej.commons/${project.version} - mvn:org.smarthomej.addons.bundles/org.smarthomej.binding.mail/${project.version} - - diff --git a/bundles/org.smarthomej.binding.mail/src/main/java/org/smarthomej/binding/mail/internal/MailBindingConstants.java b/bundles/org.smarthomej.binding.mail/src/main/java/org/smarthomej/binding/mail/internal/MailBindingConstants.java deleted file mode 100644 index 317576ded8..0000000000 --- a/bundles/org.smarthomej.binding.mail/src/main/java/org/smarthomej/binding/mail/internal/MailBindingConstants.java +++ /dev/null @@ -1,43 +0,0 @@ -/** - * Copyright (c) 2010-2021 Contributors to the openHAB project - * Copyright (c) 2021-2023 Contributors to the SmartHome/J project - * - * See the NOTICE file(s) distributed with this work for additional - * information. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0 - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.smarthomej.binding.mail.internal; - -import java.util.Arrays; -import java.util.HashSet; -import java.util.Set; - -import org.eclipse.jdt.annotation.NonNullByDefault; -import org.openhab.core.thing.ThingTypeUID; -import org.openhab.core.thing.type.ChannelTypeUID; - -/** - * The {@link MailBindingConstants} class defines common constants, which are - * used across the whole binding. - * - * @author Jan N. Klug - Initial contribution - */ -@NonNullByDefault -public class MailBindingConstants { - private static final String BINDING_ID = "mail"; - - public static final ThingTypeUID THING_TYPE_SMTPSERVER = new ThingTypeUID(BINDING_ID, "smtp"); - public static final ThingTypeUID THING_TYPE_IMAPSERVER = new ThingTypeUID(BINDING_ID, "imap"); - public static final ThingTypeUID THING_TYPE_POP3SERVER = new ThingTypeUID(BINDING_ID, "pop3"); - - public static final Set SUPPORTED_THING_TYPES = new HashSet<>( - Arrays.asList(THING_TYPE_SMTPSERVER, THING_TYPE_IMAPSERVER, THING_TYPE_POP3SERVER)); - - public static final ChannelTypeUID CHANNEL_TYPE_UID_FOLDER_MAILCOUNT = new ChannelTypeUID(BINDING_ID, "mailcount"); - public static final ChannelTypeUID CHANNEL_TYPE_UID_MAIL_CONTENT = new ChannelTypeUID(BINDING_ID, "content"); -} diff --git a/bundles/org.smarthomej.binding.mail/src/main/java/org/smarthomej/binding/mail/internal/MailBuilder.java b/bundles/org.smarthomej.binding.mail/src/main/java/org/smarthomej/binding/mail/internal/MailBuilder.java deleted file mode 100644 index c89af5d430..0000000000 --- a/bundles/org.smarthomej.binding.mail/src/main/java/org/smarthomej/binding/mail/internal/MailBuilder.java +++ /dev/null @@ -1,220 +0,0 @@ -/** - * Copyright (c) 2010-2021 Contributors to the openHAB project - * Copyright (c) 2021-2023 Contributors to the SmartHome/J project - * - * See the NOTICE file(s) distributed with this work for additional - * information. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0 - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.smarthomej.binding.mail.internal; - -import java.io.File; -import java.net.MalformedURLException; -import java.net.URL; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import javax.activation.FileDataSource; -import javax.mail.internet.AddressException; -import javax.mail.internet.InternetAddress; - -import org.apache.commons.mail.Email; -import org.apache.commons.mail.EmailAttachment; -import org.apache.commons.mail.EmailConstants; -import org.apache.commons.mail.EmailException; -import org.apache.commons.mail.HtmlEmail; -import org.apache.commons.mail.MultiPartEmail; -import org.apache.commons.mail.SimpleEmail; -import org.eclipse.jdt.annotation.NonNullByDefault; - -/** - * The {@link MailBuilder} class provides a builder for an mail. - * - * @author Jan N. Klug - Initial contribution - */ - -@NonNullByDefault -public class MailBuilder { - private String sender = ""; - private List recipients = new ArrayList<>(); - private List attachmentURLs = new ArrayList<>(); - private List attachmentFiles = new ArrayList<>(); - private Map headers = new HashMap<>(); - private String subject = "(no subject)"; - private String text = ""; - private String html = ""; - - /** - * Create a new MailBuilder - * - * @param recipients comma separated sequence of addresses (must follow RFC822 syntax) - * @throws AddressException on invalid recipient address - */ - public MailBuilder(String recipients) throws AddressException { - this.recipients.addAll(Arrays.asList(InternetAddress.parse(recipients))); - } - - /** - * Add one or more recipients - * - * @param recipients comma separated sequence of addresses (must follow RFC822 syntax) - * @return a MailBuilder - * @throws AddressException on invalid recipient address - */ - public MailBuilder withRecipients(String recipients) throws AddressException { - this.recipients.addAll(Arrays.asList(InternetAddress.parse(recipients))); - return this; - } - - /** - * Set the sender address - * - * @param sender address (must follow RFC822 syntax) - * @return a MailBuilder - */ - public MailBuilder withSender(String sender) { - this.sender = sender; - return this; - } - - /** - * Set the mail subject - * - * @param subject String containing the subject - * @return a MailBuilder - */ - public MailBuilder withSubject(String subject) { - this.subject = subject; - return this; - } - - /** - * Set the plain text content - * - * @param text String containing the text - * @return a MailBuilder - */ - public MailBuilder withText(String text) { - this.text = text; - return this; - } - - /** - * Set the HTML content - * - * @param html a String containing HTML (syntax not checked) - * @return a MailBuilder - */ - public MailBuilder withHtml(String html) { - this.html = html; - return this; - } - - /** - * Attach an URL - * - * @param urlString the URL as String - * @return a MailBuilder - * @throws MalformedURLException if url has invalid format - */ - public MailBuilder withURLAttachment(String urlString) throws MalformedURLException { - attachmentURLs.add(new URL(urlString)); - return this; - } - - /** - * Attach a file - * - * @param path String with path to local file - * @return a MailBuilder - */ - public MailBuilder withFileAttachment(String path) { - attachmentFiles.add(new File(path)); - return this; - } - - /** - * - * - * @param key the key of the header - * @param value the value of the header - * @return a MailBuilder - */ - public MailBuilder withHeader(String key, String value) { - headers.put(key, value); - return this; - } - - /** - * Build the Mail - * - * @return instance of Email - * @throws EmailException if something goes wrong - */ - public Email build() throws EmailException { - Email mail; - - if (attachmentURLs.isEmpty() && attachmentFiles.isEmpty() && html.isEmpty()) { - // text mail without attachments - mail = new SimpleEmail(); - mail.setCharset(EmailConstants.UTF_8); - if (!text.isEmpty()) { - mail.setMsg(text); - } - } else if (html.isEmpty()) { - // text mail with attachments - MultiPartEmail multipartMail = new MultiPartEmail(); - multipartMail.setCharset(EmailConstants.UTF_8); - if (!text.isEmpty()) { - multipartMail.setMsg(text); - } - for (File file : attachmentFiles) { - multipartMail.attach(file); - } - for (URL url : attachmentURLs) { - String fileName = url.toString().replaceFirst(".*/([^/?]+).*", "$1"); - multipartMail.attach(url, fileName, fileName, EmailAttachment.ATTACHMENT); - } - mail = multipartMail; - } else { - // html email - HtmlEmail htmlMail = new HtmlEmail(); - htmlMail.setCharset(EmailConstants.UTF_8); - if (!text.isEmpty()) { - // alternate text supplied - htmlMail.setTextMsg(text); - htmlMail.setHtmlMsg(html); - } else { - htmlMail.setMsg(html); - } - for (File file : attachmentFiles) { - htmlMail.attach(new FileDataSource(file), "", ""); - } - for (URL url : attachmentURLs) { - EmailAttachment attachment = new EmailAttachment(); - attachment.setURL(url); - attachment.setDisposition(EmailAttachment.ATTACHMENT); - htmlMail.attach(attachment); - } - mail = htmlMail; - } - - mail.setTo(recipients); - mail.setSubject(subject); - mail.setHeaders(headers); - - if (!sender.isEmpty()) { - mail.setFrom(sender); - } - - return mail; - } -} diff --git a/bundles/org.smarthomej.binding.mail/src/main/java/org/smarthomej/binding/mail/internal/MailCountChannelType.java b/bundles/org.smarthomej.binding.mail/src/main/java/org/smarthomej/binding/mail/internal/MailCountChannelType.java deleted file mode 100644 index 826a42bef2..0000000000 --- a/bundles/org.smarthomej.binding.mail/src/main/java/org/smarthomej/binding/mail/internal/MailCountChannelType.java +++ /dev/null @@ -1,27 +0,0 @@ -/** - * Copyright (c) 2010-2021 Contributors to the openHAB project - * Copyright (c) 2021-2023 Contributors to the SmartHome/J project - * - * See the NOTICE file(s) distributed with this work for additional - * information. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0 - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.smarthomej.binding.mail.internal; - -import org.eclipse.jdt.annotation.NonNullByDefault; - -/** - * The {@link MailCountChannelType} enum for folder mail count type - * - * @author Jan N. Klug - Initial contribution - */ -@NonNullByDefault -public enum MailCountChannelType { - UNREAD, - TOTAL -} diff --git a/bundles/org.smarthomej.binding.mail/src/main/java/org/smarthomej/binding/mail/internal/MailHandlerFactory.java b/bundles/org.smarthomej.binding.mail/src/main/java/org/smarthomej/binding/mail/internal/MailHandlerFactory.java deleted file mode 100644 index f65489af41..0000000000 --- a/bundles/org.smarthomej.binding.mail/src/main/java/org/smarthomej/binding/mail/internal/MailHandlerFactory.java +++ /dev/null @@ -1,64 +0,0 @@ -/** - * Copyright (c) 2010-2021 Contributors to the openHAB project - * Copyright (c) 2021-2023 Contributors to the SmartHome/J project - * - * See the NOTICE file(s) distributed with this work for additional - * information. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0 - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.smarthomej.binding.mail.internal; - -import static org.smarthomej.binding.mail.internal.MailBindingConstants.*; - -import org.eclipse.jdt.annotation.NonNullByDefault; -import org.eclipse.jdt.annotation.Nullable; -import org.openhab.core.thing.Thing; -import org.openhab.core.thing.ThingTypeUID; -import org.openhab.core.thing.binding.BaseThingHandlerFactory; -import org.openhab.core.thing.binding.ThingHandler; -import org.openhab.core.thing.binding.ThingHandlerFactory; -import org.osgi.service.component.annotations.Activate; -import org.osgi.service.component.annotations.Component; -import org.osgi.service.component.annotations.Reference; -import org.smarthomej.commons.transform.ValueTransformationProvider; - -/** - * The {@link MailHandlerFactory} is responsible for creating things and thing - * handlers. - * - * @author Jan N. Klug - Initial contribution - */ -@NonNullByDefault -@Component(configurationPid = "binding.mail", service = ThingHandlerFactory.class) -public class MailHandlerFactory extends BaseThingHandlerFactory { - - private final ValueTransformationProvider valueTransformationProvider; - - @Activate - public MailHandlerFactory(@Reference ValueTransformationProvider valueTransformationProvider) { - this.valueTransformationProvider = valueTransformationProvider; - } - - @Override - public boolean supportsThingType(ThingTypeUID thingTypeUID) { - return SUPPORTED_THING_TYPES.contains(thingTypeUID); - } - - @Override - protected @Nullable ThingHandler createHandler(Thing thing) { - ThingTypeUID thingTypeUID = thing.getThingTypeUID(); - - if (THING_TYPE_SMTPSERVER.equals(thingTypeUID)) { - return new SMTPHandler(thing); - } else if (THING_TYPE_IMAPSERVER.equals(thingTypeUID) || THING_TYPE_POP3SERVER.equals(thingTypeUID)) { - return new POP3IMAPHandler(thing, valueTransformationProvider); - } - - return null; - } -} diff --git a/bundles/org.smarthomej.binding.mail/src/main/java/org/smarthomej/binding/mail/internal/POP3IMAPHandler.java b/bundles/org.smarthomej.binding.mail/src/main/java/org/smarthomej/binding/mail/internal/POP3IMAPHandler.java deleted file mode 100644 index 9a65cdb6e6..0000000000 --- a/bundles/org.smarthomej.binding.mail/src/main/java/org/smarthomej/binding/mail/internal/POP3IMAPHandler.java +++ /dev/null @@ -1,220 +0,0 @@ -/** - * Copyright (c) 2010-2021 Contributors to the openHAB project - * Copyright (c) 2021-2023 Contributors to the SmartHome/J project - * - * See the NOTICE file(s) distributed with this work for additional - * information. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0 - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.smarthomej.binding.mail.internal; - -import static org.smarthomej.binding.mail.internal.MailBindingConstants.CHANNEL_TYPE_UID_FOLDER_MAILCOUNT; -import static org.smarthomej.binding.mail.internal.MailBindingConstants.CHANNEL_TYPE_UID_MAIL_CONTENT; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.util.Properties; -import java.util.concurrent.ScheduledFuture; -import java.util.concurrent.TimeUnit; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -import javax.mail.Address; -import javax.mail.Flags; -import javax.mail.Folder; -import javax.mail.Message; -import javax.mail.MessagingException; -import javax.mail.Session; -import javax.mail.Store; -import javax.mail.internet.MimeMessage; -import javax.mail.internet.MimeMultipart; -import javax.mail.search.FlagTerm; - -import org.eclipse.jdt.annotation.NonNullByDefault; -import org.eclipse.jdt.annotation.Nullable; -import org.openhab.core.library.types.DecimalType; -import org.openhab.core.library.types.StringType; -import org.openhab.core.thing.Channel; -import org.openhab.core.thing.ChannelUID; -import org.openhab.core.thing.Thing; -import org.openhab.core.thing.ThingStatus; -import org.openhab.core.thing.ThingStatusDetail; -import org.openhab.core.thing.binding.BaseThingHandler; -import org.openhab.core.types.Command; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.smarthomej.binding.mail.internal.config.POP3IMAPConfig; -import org.smarthomej.binding.mail.internal.config.POP3IMAPContentChannelConfig; -import org.smarthomej.binding.mail.internal.config.POP3IMAPMailCountChannelConfig; -import org.smarthomej.commons.transform.ValueTransformation; -import org.smarthomej.commons.transform.ValueTransformationProvider; - -/** - * The {@link POP3IMAPHandler} is responsible for handling commands, which are - * sent to one of the channels. - * - * @author Jan N. Klug - Initial contribution - */ -@NonNullByDefault -public class POP3IMAPHandler extends BaseThingHandler { - private final Logger logger = LoggerFactory.getLogger(POP3IMAPHandler.class); - - private final ValueTransformationProvider valueTransformationProvider; - - private @NonNullByDefault({}) POP3IMAPConfig config; - private @Nullable ScheduledFuture refreshTask; - private final String baseProtocol; - private String protocol = "imap"; - - public POP3IMAPHandler(Thing thing, ValueTransformationProvider valueTransformationProvider) { - super(thing); - this.valueTransformationProvider = valueTransformationProvider; - baseProtocol = thing.getThingTypeUID().getId(); // pop3 or imap - } - - @Override - public void handleCommand(ChannelUID channelUID, Command command) { - } - - @Override - public void initialize() { - config = getConfigAs(POP3IMAPConfig.class); - - protocol = baseProtocol; - - if (config.security == ServerSecurity.SSL) { - protocol = protocol.concat("s"); - } - - if (config.port == 0) { - switch (protocol) { - case "imap": - config.port = 143; - break; - case "imaps": - config.port = 993; - break; - case "pop3": - config.port = 110; - break; - case "pop3s": - config.port = 995; - break; - default: - updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR); - return; - } - } - - refreshTask = scheduler.scheduleWithFixedDelay(this::refresh, 0, config.refresh, TimeUnit.SECONDS); - updateStatus(ThingStatus.ONLINE); - } - - @Override - public void dispose() { - ScheduledFuture refreshTask = this.refreshTask; - if (refreshTask != null) { - refreshTask.cancel(true); - this.refreshTask = null; - } - } - - private void refresh() { - if (Thread.currentThread().isInterrupted()) { - return; - } - Properties props = new Properties(); - props.setProperty("mail." + baseProtocol + ".starttls.enable", "true"); - props.setProperty("mail.store.protocol", protocol); - Session session = Session.getInstance(props); - - try (Store store = session.getStore()) { - store.connect(config.hostname, config.port, config.username, config.password); - - for (Channel channel : thing.getChannels()) { - if (CHANNEL_TYPE_UID_FOLDER_MAILCOUNT.equals(channel.getChannelTypeUID())) { - final POP3IMAPMailCountChannelConfig channelConfig = channel.getConfiguration() - .as(POP3IMAPMailCountChannelConfig.class); - final String folderName = channelConfig.folder; - if (folderName == null || folderName.isEmpty()) { - logger.info("missing or empty folder name in channel {}", channel.getUID()); - } else { - try (Folder mailbox = store.getFolder(folderName)) { - mailbox.open(Folder.READ_ONLY); - if (channelConfig.type == MailCountChannelType.TOTAL) { - updateState(channel.getUID(), new DecimalType(mailbox.getMessageCount())); - } else { - updateState(channel.getUID(), new DecimalType( - mailbox.search(new FlagTerm(new Flags(Flags.Flag.SEEN), false)).length)); - } - } - } - } else if (CHANNEL_TYPE_UID_MAIL_CONTENT.equals(channel.getChannelTypeUID())) { - final POP3IMAPContentChannelConfig channelConfig = channel.getConfiguration() - .as(POP3IMAPContentChannelConfig.class); - final String folderName = channelConfig.folder; - final ValueTransformation valueTransformation = valueTransformationProvider - .getValueTransformation(channelConfig.transformation); - if (folderName == null || folderName.isEmpty()) { - logger.info("missing or empty folder name in channel '{}'", channel.getUID()); - } else { - try (Folder mailbox = store.getFolder(folderName)) { - mailbox.open(channelConfig.markAsRead ? Folder.READ_WRITE : Folder.READ_ONLY); - Message[] messages = mailbox.search(new FlagTerm(new Flags(Flags.Flag.SEEN), false)); - for (Message message : messages) { - String subject = message.getSubject(); - Address[] senders = message.getFrom(); - String sender = senders == null ? "" - : Stream.of(senders).map(Address::toString).collect(Collectors.joining(",")); - logger.debug("Processing `{}` from `{}`", subject, sender); - if (!channelConfig.subject.isBlank() && !subject.matches(channelConfig.subject)) { - logger.trace("Subject '{}' did not pass subject filter", subject); - continue; - } - if (!channelConfig.sender.isBlank() && !sender.matches(channelConfig.sender)) { - logger.trace("Sender '{}' did not pass filter '{}'", subject, channelConfig.sender); - continue; - } - Object rawContent = message.getContent(); - String contentAsString; - if (rawContent instanceof String) { - logger.trace("Detected plain text message"); - contentAsString = (String) rawContent; - } else if (rawContent instanceof MimeMessage) { - logger.trace("Detected MIME message"); - MimeMessage mimeMessage = (MimeMessage) rawContent; - try (ByteArrayOutputStream os = new ByteArrayOutputStream()) { - mimeMessage.writeTo(os); - contentAsString = os.toString(); - } - } else if (rawContent instanceof MimeMultipart) { - logger.trace("Detected MIME multipart message"); - MimeMultipart mimeMultipart = (MimeMultipart) rawContent; - try (ByteArrayOutputStream os = new ByteArrayOutputStream()) { - mimeMultipart.writeTo(os); - contentAsString = os.toString(); - } - } else { - logger.warn( - "Failed to convert mail content from '{}' with subject '{}', to String: {}", - sender, subject, rawContent.getClass()); - continue; - } - logger.trace("Found content '{}'", contentAsString); - valueTransformation.apply(contentAsString) - .ifPresent(result -> updateState(channel.getUID(), new StringType(result))); - } - } - } - } - } - } catch (MessagingException | IOException e) { - logger.info("Failed refreshing IMAP for thing '{}': {}", thing.getUID(), e.getMessage()); - } - } -} diff --git a/bundles/org.smarthomej.binding.mail/src/main/java/org/smarthomej/binding/mail/internal/SMTPHandler.java b/bundles/org.smarthomej.binding.mail/src/main/java/org/smarthomej/binding/mail/internal/SMTPHandler.java deleted file mode 100644 index 42a509f59b..0000000000 --- a/bundles/org.smarthomej.binding.mail/src/main/java/org/smarthomej/binding/mail/internal/SMTPHandler.java +++ /dev/null @@ -1,144 +0,0 @@ -/** - * Copyright (c) 2010-2021 Contributors to the openHAB project - * Copyright (c) 2021-2023 Contributors to the SmartHome/J project - * - * See the NOTICE file(s) distributed with this work for additional - * information. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0 - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.smarthomej.binding.mail.internal; - -import java.lang.reflect.Field; -import java.util.Collection; -import java.util.List; - -import javax.activation.DataHandler; -import javax.activation.DataSource; -import javax.activation.PatchedMailcapCommandMap; -import javax.mail.MessagingException; -import javax.mail.Part; -import javax.mail.internet.MimeMultipart; - -import org.apache.commons.mail.DefaultAuthenticator; -import org.apache.commons.mail.Email; -import org.apache.commons.mail.EmailException; -import org.eclipse.jdt.annotation.NonNullByDefault; -import org.openhab.core.thing.ChannelUID; -import org.openhab.core.thing.Thing; -import org.openhab.core.thing.ThingStatus; -import org.openhab.core.thing.binding.BaseThingHandler; -import org.openhab.core.thing.binding.ThingHandlerService; -import org.openhab.core.types.Command; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.smarthomej.binding.mail.internal.action.SendMailActions; -import org.smarthomej.binding.mail.internal.config.SMTPConfig; - -/** - * The {@link SMTPHandler} is responsible for handling commands, which are - * sent to one of the channels. - * - * @author Jan N. Klug - Initial contribution - */ -@NonNullByDefault -public class SMTPHandler extends BaseThingHandler { - private final Logger logger = LoggerFactory.getLogger(SMTPHandler.class); - private final PatchedMailcapCommandMap commandMap = new PatchedMailcapCommandMap(); - - private @NonNullByDefault({}) SMTPConfig config; - - public SMTPHandler(Thing thing) { - super(thing); - } - - @Override - public void handleCommand(ChannelUID channelUID, Command command) { - } - - @Override - public void initialize() { - config = getConfigAs(SMTPConfig.class); - - if (config.port == 0) { - if (config.security == ServerSecurity.SSL) { - config.port = 465; - } else { - config.port = 25; - } - } - - updateStatus(ThingStatus.ONLINE); - } - - /** - * use this server to send a mail - * - * @param mail the Email that needs to be sent - * @return true if successful, false if failed - */ - public boolean sendMail(Email mail) { - try { - if (mail.getFromAddress() == null) { - mail.setFrom(config.sender); - } - mail.setHostName(config.hostname); - switch (config.security) { - case SSL: - mail.setSSLOnConnect(true); - mail.setSslSmtpPort(config.port.toString()); - break; - case STARTTLS: - mail.setStartTLSEnabled(true); - mail.setStartTLSRequired(true); - mail.setSmtpPort(config.port); - break; - case PLAIN: - mail.setSmtpPort(config.port); - } - if (!config.username.isEmpty() && !config.password.isEmpty()) { - mail.setAuthenticator(new DefaultAuthenticator(config.username, config.password)); - } - - mail.buildMimeMessage(); - - // fix command map not available - DataHandler dataHandler = mail.getMimeMessage().getDataHandler(); - dataHandler.setCommandMap(commandMap); - try { - DataSource dataSource = dataHandler.getDataSource(); - Field dataField = dataSource.getClass().getDeclaredField("data"); - dataField.setAccessible(true); - Object data = dataField.get(dataSource); - if (data instanceof MimeMultipart) { - MimeMultipart mimeMultipart = (MimeMultipart) data; - for (int i = 0; i < mimeMultipart.getCount(); i++) { - Part mimePart = mimeMultipart.getBodyPart(i); - mimePart.getDataHandler().setCommandMap(commandMap); - } - } - } catch (NoSuchFieldException | IllegalAccessException ignored) { - } - - mail.sendMimeMessage(); - } catch (MessagingException | EmailException e) { - Throwable cause = e.getCause(); - if (cause != null) { - logger.warn("{}", cause.toString()); - } else { - logger.warn("{}", e.getMessage()); - } - return false; - } - return true; - } - - @Override - public Collection> getServices() { - return List.of(SendMailActions.class); - } -} diff --git a/bundles/org.smarthomej.binding.mail/src/main/java/org/smarthomej/binding/mail/internal/ServerSecurity.java b/bundles/org.smarthomej.binding.mail/src/main/java/org/smarthomej/binding/mail/internal/ServerSecurity.java deleted file mode 100644 index fa03b0e28a..0000000000 --- a/bundles/org.smarthomej.binding.mail/src/main/java/org/smarthomej/binding/mail/internal/ServerSecurity.java +++ /dev/null @@ -1,28 +0,0 @@ -/** - * Copyright (c) 2010-2021 Contributors to the openHAB project - * Copyright (c) 2021-2023 Contributors to the SmartHome/J project - * - * See the NOTICE file(s) distributed with this work for additional - * information. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0 - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.smarthomej.binding.mail.internal; - -import org.eclipse.jdt.annotation.NonNullByDefault; - -/** - * The {@link ServerSecurity} enum contains security configuration options - * - * @author Jan N. Klug - Initial contribution - */ -@NonNullByDefault -public enum ServerSecurity { - PLAIN, - SSL, - STARTTLS -} diff --git a/bundles/org.smarthomej.binding.mail/src/main/java/org/smarthomej/binding/mail/internal/action/SendMailActions.java b/bundles/org.smarthomej.binding.mail/src/main/java/org/smarthomej/binding/mail/internal/action/SendMailActions.java deleted file mode 100644 index 0a1cec972c..0000000000 --- a/bundles/org.smarthomej.binding.mail/src/main/java/org/smarthomej/binding/mail/internal/action/SendMailActions.java +++ /dev/null @@ -1,281 +0,0 @@ -/** - * Copyright (c) 2010-2021 Contributors to the openHAB project - * Copyright (c) 2021-2023 Contributors to the SmartHome/J project - * - * See the NOTICE file(s) distributed with this work for additional - * information. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0 - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.smarthomej.binding.mail.internal.action; - -import java.net.MalformedURLException; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -import javax.mail.internet.AddressException; - -import org.apache.commons.mail.EmailException; -import org.eclipse.jdt.annotation.NonNullByDefault; -import org.eclipse.jdt.annotation.Nullable; -import org.openhab.core.automation.annotation.ActionInput; -import org.openhab.core.automation.annotation.ActionOutput; -import org.openhab.core.automation.annotation.RuleAction; -import org.openhab.core.thing.binding.ThingActions; -import org.openhab.core.thing.binding.ThingActionsScope; -import org.openhab.core.thing.binding.ThingHandler; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.smarthomej.binding.mail.internal.MailBuilder; -import org.smarthomej.binding.mail.internal.SMTPHandler; - -/** - * The {@link SendMailActions} class defines rule actions for sending mail - * - * @author Jan N. Klug - Initial contribution - */ -@ThingActionsScope(name = "mail") -@NonNullByDefault -@SuppressWarnings("unused") -public class SendMailActions implements ThingActions { - - private final Logger logger = LoggerFactory.getLogger(SendMailActions.class); - - private @Nullable SMTPHandler handler; - - // plain text actions - - @RuleAction(label = "@text/sendMessageActionLabel", description = "@text/sendMessageActionDescription") - public @ActionOutput(name = "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) { - return sendComplexMail(recipient, subject, text, List.of(), null); - } - - @RuleAction(label = "@text/sendAttachmentMessageActionLabel", description = "@text/sendAttachmentMessageActionDescription") - public @ActionOutput(name = "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 urlString) { - List urlList = new ArrayList<>(); - if (urlString != null) { - urlList.add(urlString); - } - return sendComplexMail(recipient, subject, text, urlList, null); - } - - @RuleAction(label = "@text/sendAttachmentsMessageActionLabel", description = "@text/sendAttachmentsMessageActionDescription") - public @ActionOutput(name = "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") @Nullable List urlStringList) { - return sendComplexMail(recipient, subject, text, urlStringList, null); - } - - @RuleAction(label = "@text/sendComplexMessageActionLabel", description = "@text/sendComplexMessageActionDescription") - public @ActionOutput(name = "success", type = "java.lang.Boolean") Boolean sendComplexMail( - @ActionInput(name = "recipient") @Nullable String recipient, - @ActionInput(name = "subject") @Nullable String subject, @ActionInput(name = "text") @Nullable String text, - @ActionInput(name = "urlList") @Nullable List urlStringList, - @ActionInput(name = "headers") @Nullable Map headers) { - if (recipient == null) { - logger.warn("Cannot send mail as recipient is missing."); - return false; - } - - try { - MailBuilder builder = new MailBuilder(recipient); - - if (subject != null && !subject.isEmpty()) { - builder.withSubject(subject); - } - if (text != null && !text.isEmpty()) { - builder.withText(text); - } - if (urlStringList != null) { - for (String urlString : urlStringList) { - builder.withURLAttachment(urlString); - } - } - - if (headers != null) { - headers.forEach(builder::withHeader); - } - - final SMTPHandler handler = this.handler; - if (handler == null) { - logger.info("Handler is null, cannot send mail."); - return false; - } else { - return handler.sendMail(builder.build()); - } - } catch (AddressException | MalformedURLException | EmailException e) { - logger.warn("Could not send mail: {}", e.getMessage()); - return false; - } - } - - public static boolean sendMail(ThingActions actions, @Nullable String recipient, @Nullable String subject, - @Nullable String text) { - return SendMailActions.sendComplexMail(actions, recipient, subject, text, List.of(), null); - } - - public static boolean sendMailWithAttachment(ThingActions actions, @Nullable String recipient, - @Nullable String subject, @Nullable String text, @Nullable String urlString) { - List urlList = new ArrayList<>(); - if (urlString != null) { - urlList.add(urlString); - } - return SendMailActions.sendComplexMail(actions, recipient, subject, text, urlList, null); - } - - @Deprecated - public static boolean sendMail(ThingActions actions, @Nullable String recipient, @Nullable String subject, - @Nullable String text, @Nullable String urlString) { - return SendMailActions.sendMailWithAttachment(actions, recipient, subject, text, urlString); - } - - public static boolean sendMailWithAttachments(ThingActions actions, @Nullable String recipient, - @Nullable String subject, @Nullable String text, @Nullable List urlStringList) { - return SendMailActions.sendComplexMail(actions, recipient, subject, text, urlStringList, null); - } - - @Deprecated - public static boolean sendMail(ThingActions actions, @Nullable String recipient, @Nullable String subject, - @Nullable String text, @Nullable List urlStringList) { - return SendMailActions.sendMailWithAttachments(actions, recipient, subject, text, urlStringList); - } - - public static boolean sendComplexMail(ThingActions actions, @Nullable String recipient, @Nullable String subject, - @Nullable String text, @Nullable List urlStringList, @Nullable Map headers) { - return ((SendMailActions) actions).sendComplexMail(recipient, subject, text, urlStringList, headers); - } - - // HTML actions - - @RuleAction(label = "@text/sendHTMLMessageActionLabel", description = "@text/sendHTMLMessageActionDescription") - public @ActionOutput(name = "success", type = "java.lang.Boolean") Boolean sendHtmlMail( - @ActionInput(name = "recipient") @Nullable String recipient, - @ActionInput(name = "subject") @Nullable String subject, - @ActionInput(name = "html") @Nullable String html) { - return sendHtmlMailWithAttachments(recipient, subject, html, List.of()); - } - - @RuleAction(label = "@text/sendHTMLAttachmentMessageActionLabel", description = "@text/sendHTMLAttachmentMessageActionDescription") - public @ActionOutput(name = "success", type = "java.lang.Boolean") Boolean sendHtmlMailWithAttachment( - @ActionInput(name = "recipient") @Nullable String recipient, - @ActionInput(name = "subject") @Nullable String subject, @ActionInput(name = "html") @Nullable String html, - @ActionInput(name = "url") @Nullable String urlString) { - List urlList = new ArrayList<>(); - if (urlString != null) { - urlList.add(urlString); - } - return sendHtmlMailWithAttachments(recipient, subject, html, urlList); - } - - @RuleAction(label = "@text/sendHTMLAttachmentsMessageActionLabel", description = "@text/sendHTMLAttachmentsMessageActionDescription") - public @ActionOutput(name = "success", type = "java.lang.Boolean") Boolean sendHtmlMailWithAttachments( - @ActionInput(name = "recipient") @Nullable String recipient, - @ActionInput(name = "subject") @Nullable String subject, @ActionInput(name = "html") @Nullable String html, - @ActionInput(name = "urlList") @Nullable List urlStringList) { - return sendComplexHtmlMail(recipient, subject, html, urlStringList, null); - } - - @RuleAction(label = "@text/sendComplexHTMLMessageActionLabel", description = "@text/sendComplexHTMLMessageActionDescription") - public @ActionOutput(name = "success", type = "java.lang.Boolean") Boolean sendComplexHtmlMail( - @ActionInput(name = "recipient") @Nullable String recipient, - @ActionInput(name = "subject") @Nullable String subject, @ActionInput(name = "html") @Nullable String html, - @ActionInput(name = "urlList") @Nullable List urlStringList, - @ActionInput(name = "headers") @Nullable Map headers) { - if (recipient == null) { - logger.warn("Cannot send mail as recipient is missing."); - return false; - } - - try { - MailBuilder builder = new MailBuilder(recipient); - - if (subject != null && !subject.isEmpty()) { - builder.withSubject(subject); - } - if (html != null && !html.isEmpty()) { - builder.withHtml(html); - } - if (urlStringList != null) { - for (String urlString : urlStringList) { - builder.withURLAttachment(urlString); - } - } - - if (headers != null) { - headers.forEach(builder::withHeader); - } - - final SMTPHandler handler = this.handler; - if (handler == null) { - logger.warn("Handler is null, cannot send mail."); - return false; - } else { - return handler.sendMail(builder.build()); - } - } catch (AddressException | MalformedURLException | EmailException e) { - logger.warn("Could not send mail: {}", e.getMessage()); - return false; - } - } - - public static boolean sendHtmlMail(ThingActions actions, @Nullable String recipient, @Nullable String subject, - @Nullable String html) { - return SendMailActions.sendComplexHtmlMail(actions, recipient, subject, html, List.of(), null); - } - - public static boolean sendHtmlMailWithAttachment(ThingActions actions, @Nullable String recipient, - @Nullable String subject, @Nullable String html, @Nullable String urlString) { - List urlList = new ArrayList<>(); - if (urlString != null) { - urlList.add(urlString); - } - return SendMailActions.sendComplexHtmlMail(actions, recipient, subject, html, urlList, null); - } - - @Deprecated - public static boolean sendHtmlMail(ThingActions actions, @Nullable String recipient, @Nullable String subject, - @Nullable String html, @Nullable String urlString) { - return SendMailActions.sendHtmlMailWithAttachment(actions, recipient, subject, html, urlString); - } - - public static boolean sendHtmlMailWithAttachments(ThingActions actions, @Nullable String recipient, - @Nullable String subject, @Nullable String html, @Nullable List urlStringList) { - return SendMailActions.sendComplexHtmlMail(actions, recipient, subject, html, urlStringList, null); - } - - @Deprecated - public static boolean sendHtmlMail(ThingActions actions, @Nullable String recipient, @Nullable String subject, - @Nullable String html, @Nullable List urlStringList) { - return SendMailActions.sendHtmlMailWithAttachments(actions, recipient, subject, html, urlStringList); - } - - public static boolean sendComplexHtmlMail(ThingActions actions, @Nullable String recipient, - @Nullable String subject, @Nullable String html, @Nullable List urlStringList, - @Nullable Map headers) { - return ((SendMailActions) actions).sendComplexHtmlMail(recipient, subject, html, urlStringList, headers); - } - - @Override - public void setThingHandler(@Nullable ThingHandler handler) { - if (handler instanceof SMTPHandler) { - this.handler = (SMTPHandler) handler; - } - } - - @Override - public @Nullable ThingHandler getThingHandler() { - return handler; - } -} diff --git a/bundles/org.smarthomej.binding.mail/src/main/java/org/smarthomej/binding/mail/internal/config/BaseConfig.java b/bundles/org.smarthomej.binding.mail/src/main/java/org/smarthomej/binding/mail/internal/config/BaseConfig.java deleted file mode 100644 index 2031bec471..0000000000 --- a/bundles/org.smarthomej.binding.mail/src/main/java/org/smarthomej/binding/mail/internal/config/BaseConfig.java +++ /dev/null @@ -1,33 +0,0 @@ -/** - * Copyright (c) 2010-2021 Contributors to the openHAB project - * Copyright (c) 2021-2023 Contributors to the SmartHome/J project - * - * See the NOTICE file(s) distributed with this work for additional - * information. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0 - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.smarthomej.binding.mail.internal.config; - -import org.eclipse.jdt.annotation.NonNullByDefault; -import org.eclipse.jdt.annotation.Nullable; -import org.smarthomej.binding.mail.internal.ServerSecurity; - -/** - * The {@link BaseConfig} class contains fields mapping thing configuration parameters. - * - * @author Jan N. Klug - Initial contribution - */ - -@NonNullByDefault -public class BaseConfig { - public @Nullable String hostname; - public Integer port = 0; - public String username = ""; - public String password = ""; - public ServerSecurity security = ServerSecurity.PLAIN; -} diff --git a/bundles/org.smarthomej.binding.mail/src/main/java/org/smarthomej/binding/mail/internal/config/POP3IMAPConfig.java b/bundles/org.smarthomej.binding.mail/src/main/java/org/smarthomej/binding/mail/internal/config/POP3IMAPConfig.java deleted file mode 100644 index dc1b03ea97..0000000000 --- a/bundles/org.smarthomej.binding.mail/src/main/java/org/smarthomej/binding/mail/internal/config/POP3IMAPConfig.java +++ /dev/null @@ -1,27 +0,0 @@ -/** - * Copyright (c) 2010-2021 Contributors to the openHAB project - * Copyright (c) 2021-2023 Contributors to the SmartHome/J project - * - * See the NOTICE file(s) distributed with this work for additional - * information. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0 - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.smarthomej.binding.mail.internal.config; - -import org.eclipse.jdt.annotation.NonNullByDefault; - -/** - * The {@link POP3IMAPConfig} class contains fields mapping thing configuration parameters. - * - * @author Jan N. Klug - Initial contribution - */ - -@NonNullByDefault -public class POP3IMAPConfig extends BaseConfig { - public int refresh = 60; -} diff --git a/bundles/org.smarthomej.binding.mail/src/main/java/org/smarthomej/binding/mail/internal/config/POP3IMAPContentChannelConfig.java b/bundles/org.smarthomej.binding.mail/src/main/java/org/smarthomej/binding/mail/internal/config/POP3IMAPContentChannelConfig.java deleted file mode 100644 index 5bb3901b77..0000000000 --- a/bundles/org.smarthomej.binding.mail/src/main/java/org/smarthomej/binding/mail/internal/config/POP3IMAPContentChannelConfig.java +++ /dev/null @@ -1,33 +0,0 @@ -/** - * Copyright (c) 2010-2021 Contributors to the openHAB project - * Copyright (c) 2021-2023 Contributors to the SmartHome/J project - * - * See the NOTICE file(s) distributed with this work for additional - * information. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0 - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.smarthomej.binding.mail.internal.config; - -import org.eclipse.jdt.annotation.NonNullByDefault; -import org.eclipse.jdt.annotation.Nullable; - -/** - * The {@link POP3IMAPContentChannelConfig} class contains fields mapping thing configuration parameters. - * - * @author Jan N. Klug - Initial contribution - */ - -@NonNullByDefault -public class POP3IMAPContentChannelConfig { - public @Nullable String folder; - public String subject = ""; - public String sender = ""; - public @Nullable String transformation; - - public boolean markAsRead = false; -} diff --git a/bundles/org.smarthomej.binding.mail/src/main/java/org/smarthomej/binding/mail/internal/config/POP3IMAPMailCountChannelConfig.java b/bundles/org.smarthomej.binding.mail/src/main/java/org/smarthomej/binding/mail/internal/config/POP3IMAPMailCountChannelConfig.java deleted file mode 100644 index e912c5092c..0000000000 --- a/bundles/org.smarthomej.binding.mail/src/main/java/org/smarthomej/binding/mail/internal/config/POP3IMAPMailCountChannelConfig.java +++ /dev/null @@ -1,30 +0,0 @@ -/** - * Copyright (c) 2010-2021 Contributors to the openHAB project - * Copyright (c) 2021-2023 Contributors to the SmartHome/J project - * - * See the NOTICE file(s) distributed with this work for additional - * information. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0 - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.smarthomej.binding.mail.internal.config; - -import org.eclipse.jdt.annotation.NonNullByDefault; -import org.eclipse.jdt.annotation.Nullable; -import org.smarthomej.binding.mail.internal.MailCountChannelType; - -/** - * The {@link POP3IMAPMailCountChannelConfig} class contains fields mapping thing configuration parameters. - * - * @author Jan N. Klug - Initial contribution - */ - -@NonNullByDefault -public class POP3IMAPMailCountChannelConfig { - public @Nullable String folder; - public MailCountChannelType type = MailCountChannelType.TOTAL; -} diff --git a/bundles/org.smarthomej.binding.mail/src/main/java/org/smarthomej/binding/mail/internal/config/SMTPConfig.java b/bundles/org.smarthomej.binding.mail/src/main/java/org/smarthomej/binding/mail/internal/config/SMTPConfig.java deleted file mode 100644 index f6586c6471..0000000000 --- a/bundles/org.smarthomej.binding.mail/src/main/java/org/smarthomej/binding/mail/internal/config/SMTPConfig.java +++ /dev/null @@ -1,28 +0,0 @@ -/** - * Copyright (c) 2010-2021 Contributors to the openHAB project - * Copyright (c) 2021-2023 Contributors to the SmartHome/J project - * - * See the NOTICE file(s) distributed with this work for additional - * information. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0 - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.smarthomej.binding.mail.internal.config; - -import org.eclipse.jdt.annotation.NonNullByDefault; -import org.eclipse.jdt.annotation.Nullable; - -/** - * The {@link SMTPConfig} class contains fields mapping thing configuration parameters. - * - * @author Jan N. Klug - Initial contribution - */ - -@NonNullByDefault -public class SMTPConfig extends BaseConfig { - public @Nullable String sender; -} diff --git a/bundles/org.smarthomej.binding.mail/src/main/resources/OH-INF/addon/addon.xml b/bundles/org.smarthomej.binding.mail/src/main/resources/OH-INF/addon/addon.xml deleted file mode 100644 index 2d9a834dd5..0000000000 --- a/bundles/org.smarthomej.binding.mail/src/main/resources/OH-INF/addon/addon.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - binding - Mail Binding - This binding is used to access POP3, IMAP and SMTP servers. - - diff --git a/bundles/org.smarthomej.binding.mail/src/main/resources/OH-INF/i18n/mail.properties b/bundles/org.smarthomej.binding.mail/src/main/resources/OH-INF/i18n/mail.properties deleted file mode 100644 index 093f3378b7..0000000000 --- a/bundles/org.smarthomej.binding.mail/src/main/resources/OH-INF/i18n/mail.properties +++ /dev/null @@ -1,24 +0,0 @@ -# actions -sendMessageActionLabel = send a text mail -sendMessageActionDescription = Sends a text mail. - -sendAttachmentMessageActionLabel = send a text mail with attachment -sendAttachmentMessageActionDescription = Sends a text mail with an URL attachment. - -sendAttachmentsMessageActionLabel = send a text mail with several attachments -sendAttachmentsMessageActionDescription = Sends a text mail with several URL attachments. - -sendComplexMessageActionLabel = send a text mail with several attachments and/or additional headers -sendComplexMessageActionDescription = Sends a text mail with several URL attachments and/or additional headers. - -sendHTMLMessageActionLabel = send an HTML mail -sendHTMLMessageActionDescription = Sends an HTML mail. - -sendHTMLAttachmentMessageActionLabel = send an HTML mail with attachment -sendHTMLAttachmentMessageActionDescription = Sends an HTML mail with an URL attachment. - -sendHTMLAttachmentsMessageActionLabel = send an HTML mail with several attachments -sendHTMLAttachmentsMessageActionDescription = Sends an HTML mail with several URL attachments. - -sendComplexHtmlMessageActionLabel = send an html mail with several attachments and/or additional headers -sendComplexHtmlMessageActionDescription = Sends an HTML mail with several URL attachments and/or additional headers. diff --git a/bundles/org.smarthomej.binding.mail/src/main/resources/OH-INF/i18n/mail_de.properties b/bundles/org.smarthomej.binding.mail/src/main/resources/OH-INF/i18n/mail_de.properties deleted file mode 100644 index 657065d1ee..0000000000 --- a/bundles/org.smarthomej.binding.mail/src/main/resources/OH-INF/i18n/mail_de.properties +++ /dev/null @@ -1,95 +0,0 @@ -# binding -binding.mail.name = Mail Binding -binding.mail.description = Unterstützung von POP3, IMAP und SMTP Servern - -# thing types -thing-type.mail.smtp.label = SMTP Server -thing-type.mail.smtp.description = Wird zum Versenden von E-Mails verwendet -thing-type.config.mail.smtp.sender.label = Absender -thing-type.config.mail.smtp.sender.description = Standard-Absender für E-Mails -thing-type.config.mail.smtp.hostname.label = IP-Adresse -thing-type.config.mail.smtp.hostname.description = IP-Adresse oder Hostname des SMTP Servers -thing-type.config.mail.smtp.port.label = Port -thing-type.config.mail.smtp.port.description = Standard Ports sind 25 für PLAIN/STARTTLS und 465 für SSL/TLS -thing-type.config.mail.smtp.security.label = Sicherheitsprotokoll -thing-type.config.mail.smtp.security.description = Server Sicherheitsprotokoll zur Kommunikation mit dem SMTP Server -thing-type.config.mail.smtp.username.label = Benutzer -thing-type.config.mail.smtp.username.description = Benutzer zur Authentifizierung am SMTP Server -thing-type.config.mail.smtp.password.label = Passwort -thing-type.config.mail.smtp.password.description = Passwort zur Authentifizierung am SMTP Server - -thing-type.mail.imap.label = IMAP Server -thing-type.mail.imap.description = IMAP Postfach Überwachung -thing-type.config.mail.imap.hostname.label = IP-Adresse -thing-type.config.mail.imap.hostname.description = IP-Adresse oder Hostname des IMAP Servers -thing-type.config.mail.imap.port.label = Port -thing-type.config.mail.imap.port.description = Standard Ports sind 143 für PLAIN/STARTTLS und 993 für SSL/TLS. -thing-type.config.mail.imap.security.label = Sicherheitsprotokoll -thing-type.config.mail.imap.security.description = Server Sicherheitsprotokoll zur Kommunikation mit dem IMAP Server. -thing-type.config.mail.imap.username.label = Benutzer -thing-type.config.mail.imap.username.description = Benutzer zur Authentifizierung am IMAP Server. -thing-type.config.mail.imap.password.label = Passwort -thing-type.config.mail.imap.password.description = Passwort zur Authentifizierung am IMAP Server. -thing-type.config.mail.imap.refresh.label = Abfrageintervall -thing-type.config.mail.imap.refresh.description = Zeit zwischen zwei Abfragen (in s, Standard ist 60s). - -thing-type.mail.pop3.label = POP3 Server -thing-type.mail.pop3.description = POP3 Postfach Überwachung. -thing-type.config.mail.pop3.hostname.label = IP-Adresse -thing-type.config.mail.pop3.hostname.description = IP-Adresse oder Hostname des POP3 Servers. -thing-type.config.mail.pop3.port.label = Port -thing-type.config.mail.pop3.port.description = Standard Ports sind 110 für PLAIN/STARTTLS und 995 für SSL/TLS. -thing-type.config.mail.pop3.security.label = Sicherheitsprotokoll -thing-type.config.mail.pop3.security.description = Server Sicherheitsprotokoll zur Kommunikation mit dem POP3 Server. -thing-type.config.mail.pop3.username.label = Benutzer -thing-type.config.mail.pop3.username.description = Benutzer zur Authentifizierung am POP3 Server. -thing-type.config.mail.pop3.password.label = Passwort -thing-type.config.mail.pop3.password.description = Passwort zur Authentifizierung am POP3 Server. -thing-type.config.mail.pop3.refresh.label = Abfrageintervall -thing-type.config.mail.pop3.refresh.description = Zeit zwischen zwei Abfragen (in s, Standard ist 60s). - -channel-type.mail.mailcount.label = Anzahl -channel-type.mail.mailcount.description = Anzahl der E-Mails im Postfach. -channel-type.config.mail.mailcount.folder.label = Postfach -channel-type.config.mail.mailcount.folder.description = Name des Postfachs auf dem Server. -channel-type.config.mail.mailcount.type.label = Typ -channel-type.config.mail.mailcount.type.option.TOTAL = Gesamt -channel-type.config.mail.mailcount.type.option.UNREAD = Ungelesen - -channel-type.mail.content.label = Inhalt -channel-type.mail.content.description = Inhalt der E-Mail als Zeichenkette (mit Betreff Filter und Inhalts-Transformation). -channel-type.config.mail.content.folder.label = Postfach -channel-type.config.mail.content.folder.description = Name des Postfachs auf dem Server. -channel-type.config.mail.content.subject.label = Betreff Filter -channel-type.config.mail.content.subject.description = Ein (Regular Expression) Filter für die Betreffzeile. -channel-type.config.mail.content.sender.label = Absender Filter -channel-type.config.mail.content.sender.description = Ein (Regular Expression) Filter für die Absender-Adresse. -channel-type.config.mail.content.transformation.label = Transformation -channel-type.config.mail.content.transformation.description = Transformationsmuster für die Bearbeitung von Nachrichten. Mehrere Transformationen können mit "∩" verkettet werden. -channel-type.config.mail.content.markAsRead.label = Als Gelesen Markieren -channel-type.config.mail.content.markAsRead.description = Markiert eine Nachricht nach der Bearbeitung als gelesen und verhindert so doppelte Bearbeitung. - -# actions -sendMessageActionLabel = eine E-Mail senden -sendMessageActionDescription = Sendet eine E-Mail. - -sendAttachmentMessageActionLabel = eine E-Mail mit Anhang senden -sendAttachmentMessageActionDescription = Sendet eine E-Mail mit Anhang. - -sendAttachmentsMessageActionLabel = eine E-Mail mit mehreren Anhängen senden -sendAttachmentsMessageActionDescription = Sendet eine E-Mail mit mehreren Anhängen. - -sendComplexMessageActionLabel = eine E-Mail mit mehreren Anhängen senden und/oder zusätzlichen Headern -sendComplexMessageActionDescription = Sendet eine E-Mail mit mehreren Anhängen und/oder zusätzlichen Headern. - -sendHTMLMessageActionLabel = eine HTML E-Mail senden -sendHTMLMessageActionDescription = Sendet eine HTML E-Mail. - -sendHTMLAttachmentMessageActionLabel = eine HTML E-Mail mit Anhang senden -sendHTMLAttachmentMessageActionDescription = Sendet eine HTML E-Mail mit Anhang. - -sendHTMLAttachmentsMessageActionLabel = eine HTML E-Mail mit mehreren Anhängen senden -sendHTMLAttachmentsMessageActionDescription = Sendet eine HTML E-Mail mit mehreren Anhängen. - -sendComplexHtmlMessageActionLabel = eine HTML E-Mail mit mehreren Anhängen senden und/oder zusätzlichen Headern -sendComplexHtmlMessageActionDescription = Sendet eine HTML E-Mail mit mehreren Anhängen und/oder zusätzlichen Headern. diff --git a/bundles/org.smarthomej.binding.mail/src/main/resources/OH-INF/thing/thing-types.xml b/bundles/org.smarthomej.binding.mail/src/main/resources/OH-INF/thing/thing-types.xml deleted file mode 100644 index f7b4723fb8..0000000000 --- a/bundles/org.smarthomej.binding.mail/src/main/resources/OH-INF/thing/thing-types.xml +++ /dev/null @@ -1,163 +0,0 @@ - - - - - - Used for sending emails via rule actions - - - - Default sender address for mail - - - - - - - Default values are 25 for plain/STARTTLS and 465 for SSL/TLS - true - - - - - - - - - true - PLAIN - - - - - - - password - - - - - - Used for receiving emails - - - - - - - Default values are 143 for plain/STARTTLS and 993 for SSL/TLS - true - - - - - - - - - true - PLAIN - - - - - - - password - - - - Refresh time for this account - 60 - - - - - - Used for receiving emails - - - - - - - Default values are 110 for plain/STARTTLS and 995 for SSL/TLS - true - - - - - - - - - true - PLAIN - - - - - - - password - - - - Refresh time for this account - 60 - - - - - - Number - - Number of emails in folder - - - - - - - - - - - true - TOTAL - - - - - - String - - Mail content as String (with subject filter and content transformation). - - - - - - - - A (regular expression) filter for the mail subject. - - - - A (regular expression) filter for the mail sender address. - - - - Transformation pattern used when processing messages. Multiple transformation can be chained using "∩". - - - - Mark a processed mail as read and prevent further processing. - false - - - - diff --git a/bundles/org.smarthomej.binding.mail/src/test/java/org/smarthomej/binding/mail/MailBuilderTest.java b/bundles/org.smarthomej.binding.mail/src/test/java/org/smarthomej/binding/mail/MailBuilderTest.java deleted file mode 100644 index b0ad357f2f..0000000000 --- a/bundles/org.smarthomej.binding.mail/src/test/java/org/smarthomej/binding/mail/MailBuilderTest.java +++ /dev/null @@ -1,101 +0,0 @@ -/** - * Copyright (c) 2010-2021 Contributors to the openHAB project - * Copyright (c) 2021-2023 Contributors to the SmartHome/J project - * - * See the NOTICE file(s) distributed with this work for additional - * information. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0 - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.smarthomej.binding.mail; - -import static org.hamcrest.CoreMatchers.instanceOf; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.jupiter.api.Assertions.*; - -import java.io.IOException; -import java.net.MalformedURLException; -import java.util.Map; - -import javax.mail.MessagingException; -import javax.mail.internet.AddressException; - -import org.apache.commons.mail.Email; -import org.apache.commons.mail.EmailException; -import org.apache.commons.mail.HtmlEmail; -import org.apache.commons.mail.MultiPartEmail; -import org.apache.commons.mail.SimpleEmail; -import org.eclipse.jdt.annotation.NonNullByDefault; -import org.junit.jupiter.api.Test; -import org.smarthomej.binding.mail.internal.MailBuilder; - -/** - * The {@link MailBuilderTest} class defines tests for the {@link MailBuilder} class - * - * @author Jan N. Klug - Initial contribution - */ -@NonNullByDefault -public class MailBuilderTest { - - private static final String TEST_STRING = "test"; - private static final String TEST_EMAIL = "foo@bar.zinga"; - - @Test - public void illegalToAddressThrowsException() { - assertThrows(AddressException.class, () -> new MailBuilder("foo bar.zinga")); - } - - @Test - public void illegalFromAddressThrowsException() { - assertThrows(EmailException.class, () -> new MailBuilder("TEST_EMAIL").withSender("foo bar.zinga").build()); - } - - @Test - public void illegalURLThrowsException() { - assertThrows(MalformedURLException.class, - () -> new MailBuilder("TEST_EMAIL").withURLAttachment("foo bar.zinga")); - } - - @Test - public void withTextOnlyReturnsSimpleEmail() throws AddressException, EmailException { - MailBuilder builder = new MailBuilder(TEST_EMAIL); - Email mail = builder.withText("boo").build(); - assertThat(mail, instanceOf(SimpleEmail.class)); - } - - @Test - public void withURLAttachmentReturnsMultiPartEmail() - throws AddressException, EmailException, MalformedURLException { - MailBuilder builder = new MailBuilder(TEST_EMAIL); - Email mail = builder.withText("boo").withURLAttachment("http://www.openhab.org").build(); - assertThat(mail, instanceOf(MultiPartEmail.class)); - } - - @Test - public void withHtmlReturnsHtmlEmail() throws AddressException, EmailException { - MailBuilder builder = new MailBuilder(TEST_EMAIL); - Email mail = builder.withHtml("test").build(); - assertThat(mail, instanceOf(HtmlEmail.class)); - } - - @Test - public void fieldsSetInMail() throws EmailException, MessagingException, IOException { - MailBuilder builder = new MailBuilder(TEST_EMAIL); - - assertEquals("(no subject)", builder.build().getSubject()); - assertEquals(TEST_STRING, builder.withSubject(TEST_STRING).build().getSubject()); - - assertEquals(TEST_EMAIL, builder.withSender(TEST_EMAIL).build().getFromAddress().getAddress()); - - assertEquals(TEST_EMAIL, builder.build().getToAddresses().get(0).getAddress()); - assertEquals(2, builder.withRecipients(TEST_EMAIL).build().getToAddresses().size()); - - Map headers = builder.withHeader(TEST_STRING, TEST_STRING).build().getHeaders(); - assertEquals(1, headers.size()); - assertEquals(TEST_STRING, headers.get(TEST_STRING)); - } -} diff --git a/bundles/pom.xml b/bundles/pom.xml index 026877d7f8..819348622d 100644 --- a/bundles/pom.xml +++ b/bundles/pom.xml @@ -26,7 +26,6 @@ org.smarthomej.binding.amazonechocontrol org.smarthomej.binding.http org.smarthomej.binding.knx - org.smarthomej.binding.mail org.smarthomej.binding.notificationsforfiretv org.smarthomej.binding.tcpudp org.smarthomej.binding.telenot