[mail] Support chaining transformations without an intersection symbol (#17314)

Signed-off-by: Jimmy Tanagra <jcode@tanagra.id.au>
This commit is contained in:
jimtng 2024-08-24 02:48:52 +10:00 committed by GitHub
parent e18192f7cc
commit ac219b509b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 12 additions and 5 deletions

View File

@ -69,7 +69,10 @@ Filters use regular expressions (e.g. `.*DHL.*` as `sender` would match all From
If a parameter is left empty, no filter is applied. If a parameter is left empty, no filter is applied.
The `transformation` is applied before setting the channel status. 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. Transformations are defined using this syntax: `TYPE(FUNCTION)`, e.g.: `JSONPATH($.path)`.
The syntax: `TYPE:FUNCTION` is still supported, e.g.: `JSONPATH:$.path`.
Transformations can be chained in the UI by listing each transformation on a separate line, or by separating them with the mathematical intersection character "∩".
For example, `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). 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. 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.

View File

@ -12,6 +12,8 @@
*/ */
package org.openhab.binding.mail.internal.config; package org.openhab.binding.mail.internal.config;
import java.util.List;
import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jdt.annotation.Nullable;
@ -25,7 +27,7 @@ public class POP3IMAPContentChannelConfig {
public @Nullable String folder; public @Nullable String folder;
public String subject = ""; public String subject = "";
public String sender = ""; public String sender = "";
public @Nullable String transformation; public @Nullable List<String> transformation;
public boolean markAsRead = false; public boolean markAsRead = false;
} }

View File

@ -37,7 +37,7 @@ channel-type.config.mail.content.sender.description = A (regular expression) fil
channel-type.config.mail.content.subject.label = Subject Filter channel-type.config.mail.content.subject.label = Subject Filter
channel-type.config.mail.content.subject.description = A (regular expression) filter for the mail subject. channel-type.config.mail.content.subject.description = A (regular expression) filter for the mail subject.
channel-type.config.mail.content.transformation.label = Transformation channel-type.config.mail.content.transformation.label = Transformation
channel-type.config.mail.content.transformation.description = Transformation pattern used when processing messages. Multiple transformation can be chained using "∩". channel-type.config.mail.content.transformation.description = Transformation pattern used when processing messages. Multiple transformations can be chained by listing each transformation on a separate line, or by concatenating them with "∩".
channel-type.config.mail.mailcount.folder.label = Folder Name channel-type.config.mail.mailcount.folder.label = Folder Name
channel-type.config.mail.mailcount.type.label = Counter Type channel-type.config.mail.mailcount.type.label = Counter Type
channel-type.config.mail.mailcount.type.option.UNREAD = Unread channel-type.config.mail.mailcount.type.option.UNREAD = Unread

View File

@ -150,9 +150,11 @@
<label>Sender Filter</label> <label>Sender Filter</label>
<description>A (regular expression) filter for the mail sender address.</description> <description>A (regular expression) filter for the mail sender address.</description>
</parameter> </parameter>
<parameter name="transformation" type="text"> <parameter name="transformation" type="text" multiple="true">
<label>Transformation</label> <label>Transformation</label>
<description>Transformation pattern used when processing messages. Multiple transformation can be chained using "∩".</description> <description>Transformation pattern used when processing messages. Multiple transformations can be chained by
listing
each transformation on a separate line, or by concatenating them with "∩".</description>
</parameter> </parameter>
<parameter name="markAsRead" type="boolean"> <parameter name="markAsRead" type="boolean">
<label>Mark As Read</label> <label>Mark As Read</label>