Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .docs/banks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ A bank is in one of three states:
| MONETA | samples only | incoming and outgoing; counter-account, symbol from the description | own account (masked), transaction id, balance; payments under 100 Kč are never sent | [moneta](cz/moneta/README.md) |
| Creditas | samples only | incoming and outgoing; counter-account, symbol, balance | transaction id, name, message; card holds refused | [creditas](cz/creditas/README.md) |
| Raiffeisenbank | samples only | transfers and card payments, from HTML; names, symbols, message, balance | transaction id | [raiffeisenbank](cz/raiffeisenbank/README.md) |
| UniCredit Bank | samples only | incoming, from HTML; counter-account and name, symbols, message | transaction id, balance, type; how an outgoing payment writes its direction | [unicredit](cz/unicredit/README.md) |
| Komerční banka | not yet | | | [#14](https://github.com/landsman/bank-java/issues/14) |
| Česká spořitelna | not yet | | | [#15](https://github.com/landsman/bank-java/issues/15) |
| ČSOB | not yet | | several transactions in one e-mail | [#16](https://github.com/landsman/bank-java/issues/16) |
| UniCredit Bank | not yet | | HTML | [#19](https://github.com/landsman/bank-java/issues/19) |
| Citfin | not yet | | | [#21](https://github.com/landsman/bank-java/issues/21) |
| Partners Banka | not yet | | sends no e-mail at all | [#25](https://github.com/landsman/bank-java/issues/25) |

Expand Down
40 changes: 40 additions & 0 deletions .docs/banks/cz/unicredit/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# How UniCredit Bank's e-mail behaves

**Not seen as a real e-mail yet (2026-11-10).** The parser follows the one sanitised sample in
[radekhulan/myinvoice](https://github.com/radekhulan/myinvoice/blob/master/api/tests/Unit/Bank/UnicreditBankEmailNoticeParserTest.php)
(MIT), whose accounts fail the modulo 11 check. No key is pinned, so `withDns()` refuses every UniCredit e-mail as
`Unverified`; see [#19](https://github.com/landsman/bank-java/issues/19).

**Before a key is pinned, a real outgoing e-mail has to show how it writes its direction.** The parser takes the
amount's sign, as myinvoice does: none is money in, a minus is money out. The sample is incoming. If an outgoing
payment came without a minus, a refund to a customer, with the invoice's amount and symbol, would pay that invoice
again.

## What it carries

Subject `Informace o pohybu na účtu`, from `unicreditbank@unicreditgroup.cz` (`unicreditgroup.cz` is DNSSEC-signed;
`unicreditbank.cz` is not), **HTML** with `<br/>` between lines:

```
na Vašem účtu č. 123456789 (CZK) Test právě proběhla transakce s následujícími údaji:

Částka: 20,546.00 CZK
Číslo účtu protistrany: 0-987654321/0600
Název účtu protistrany: PLÁTCE DEMO s.r.o.
Variabilní symbol: 0002026017
Specifický symbol:
Detaily transakce: Faktura 2026017
Datum: 25.05.2026 13:02:31
```

- **The account has no bank code**: `/2700` is added. Its currency, in parentheses, has to be the amount's. The
account's nickname (`Test`) sits before `právě`.
- **Amounts are written the English way**: a comma between thousands, a dot before the decimals.
- **Every label is printed, an empty one too**, so the `Variabilní symbol` line is required exactly once: a forged one,
smuggled in through the counter-party's name, makes a second.
- **No transaction id, no balance**, no movement type (`type()` is `GENERAL`).

## Setting it up

[Fakturoid's guide](https://www.fakturoid.cz/podpora/parovani/unicredit): Nastavení → Notifikace → Vytvořit notifikace
pro transakce; Všechny transakce over 1 Kč.
4 changes: 4 additions & 0 deletions .docs/setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ See [creditas.md](banks/cz/creditas/README.md#setting-it-up). Not verified yet:

See [raiffeisenbank.md](banks/cz/raiffeisenbank/README.md#setting-it-up). Not verified yet: no real Raiffeisenbank e-mail has been read.

## UniCredit Bank

See [unicredit](banks/cz/unicredit/README.md#setting-it-up). Not verified yet: no real UniCredit e-mail has been read.

## Another bank

Not supported yet; see [banks](banks/README.md). Adding one starts from one of its real e-mails,
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ For Java 21+ and Kotlin, one jar, no framework required.

## Which banks

Air Bank and Fio banka CZ from real e-mails; MONETA, Creditas and Raiffeisenbank from public samples, until a real
Air Bank and Fio banka CZ from real e-mails; MONETA, Creditas, Raiffeisenbank and UniCredit from public samples, until a real
e-mail confirms them. Each bank, and what it reads: [banks](.docs/banks/README.md).

## Docs
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Date: Mon, 25 May 2026 13:02:54 +0200
From: UniCredit Bank <unicreditbank@unicreditgroup.cz>
To: bruce.wayne@gothba.org
Message-ID: <0000@unicreditgroup.cz>
Subject: =?utf-8?q?Informace_o_pohybu_na_=C3=BA=C4=8Dtu?=
MIME-Version: 1.0
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: 8bit

<html>Dobrý den,<br/>
na Vašem účtu č. 1234567899 (CZK) Hlavni právě proběhla transakce s následujícími údaji:<br/>
<br/>
Částka: 20,546.00 CZK<br/>
Číslo účtu protistrany: 0-9876543211/0600<br/>
Název účtu protistrany: WAYNE ENTERPRISES s.r.o.<br/>
Variabilní symbol: 0002026017<br/>
Specifický symbol: <br/>
Detaily transakce: Faktura 2026017<br/>
Datum: 25.05.2026 13:02:31<br/>
<br/>
S pozdravem,<br/>
Vaše UniCredit Bank<br/>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
package cz.insuit.bank.notification;

import cz.insuit.bank.notification.BankNotificationException.Unparsed;
import cz.insuit.bank.notification.Transaction.Direction;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.util.Currency;
import java.util.Map;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.jspecify.annotations.Nullable;

/**
* UniCredit Bank's "Informace o pohybu na účtu", from {@code unicreditbank@unicreditgroup.cz}, sent as HTML with
* {@code <br/>} between the lines.
*
* <p><b>Read from one public sample, not from a real e-mail yet</b>: the template follows the sanitised body in
* <a href="https://github.com/radekhulan/myinvoice">radekhulan/myinvoice</a> (MIT), its UniCredit parser's test. No
* key is pinned, so {@link BankNotifications#withDns()} refuses every UniCredit e-mail as unverified.
*
* <p><b>The direction is the amount's sign</b>, as in that parser: none is money in, a minus is money out. The sample
* is an incoming payment, so whether an outgoing one really carries a minus is not known. A refund to a customer has
* the invoice's amount and symbol; read as incoming, it would pay that invoice again. That is the first thing a real
* outgoing e-mail has to confirm, before any key is pinned.
*
* <p>The account in the sentence has no bank code, so {@code /2700} is added; its currency, in parentheses, has to be
* the amount's. Amounts are written the English way ({@code 20,546.00 CZK}). No transaction id, no balance.
*/
final class Unicredit implements Bank {

static final String DOMAIN = "unicreditgroup.cz";

/**
* None yet: no real e-mail has shown the selector. Before pinning one, confirm with a real outgoing e-mail how its
* direction is written (see the class comment). See {@link AirBank#KEY_FINGERPRINTS} for how keys are kept.
*/
static final Set<String> KEY_FINGERPRINTS = Set.of();

@Override
public String domain() {
return DOMAIN;
}

@Override
public Set<String> keyFingerprints() {
return KEY_FINGERPRINTS;
}

@Override
public Transaction parse(@Nullable String subject, String body) {
NotificationLines lines = new NotificationLines(body);
Matcher sentence = lines.single(SENTENCE, "opening sentence");
if (sentence == null) throw new Unparsed("no opening sentence");
// The template prints every label, an empty one too ("Specifický symbol: "), so a payment without a variable
// symbol still has its line, and a forged one, smuggled in through the counter-party's name, makes two.
if (lines.single(SYMBOL_LINE, "variable symbol") == null) throw new Unparsed("no Variabilní symbol line");
// The counter-party's name is text its holder chose; the variable symbol comes right after it.
lines.requireNext(NAME_LINE, VARIABLE_SYMBOL + ":");
// Past the details only the date follows.
Map<String, String> fields = lines.labelled(LABELLED, Set.of(DETAILS), Set.of(DATE));

String amountText = fields.get(AMOUNT);
Matcher amount = amountText == null ? null : MONEY.matcher(amountText);
if (amount == null || !amount.matches()) throw new Unparsed("amount missing or not in the known format");
if (!amount.group(4).equals(sentence.group(2))) {
throw new Unparsed("the amount's currency is not the account's");
}
Direction direction = amount.group(1).equals("-") ? Direction.OUTGOING : Direction.INCOMING;

String date = fields.get(DATE);
if (date == null) throw new Unparsed("no Datum");
LocalDateTime at;
try {
at = LocalDateTime.parse(date, DATE_TIME);
} catch (DateTimeParseException e) {
throw new Unparsed("Datum not dd.MM.yyyy HH:mm:ss: " + date);
}
String counter = fields.get(COUNTER_ACCOUNT);
try {
Money value = new Money(
new BigDecimal(amount.group(2).replace(",", "") + "." + amount.group(3)),
Currency.getInstance(amount.group(4)));
return new Transaction(
DOMAIN,
direction,
Transaction.Type.GENERAL,
BankAccount.parse(sentence.group(1) + "/" + BANK_CODE),
counter == null ? null : BankAccount.parse(counter),
fields.get(COUNTER_NAME),
direction == Direction.INCOMING ? value : value.negate(),
new PaymentSymbols(
PaymentSymbols.checked(VARIABLE_SYMBOL, fields.get(VARIABLE_SYMBOL)),
null,
PaymentSymbols.checked(SPECIFIC_SYMBOL, fields.get(SPECIFIC_SYMBOL))),
fields.get(DETAILS),
at.toLocalDate(),
null,
null,
null);
} catch (IllegalArgumentException e) {
throw new Unparsed(e.getMessage() == null ? "invalid value" : e.getMessage(), e);
}
}

// The account's nickname, the client's own text, sits between the currency and "právě".
private static final Pattern SENTENCE = Pattern.compile(
"na Vašem účtu č\\. ((?:\\d{1,6}-)?\\d{2,10}) \\(([A-Z]{3})\\) .*právě proběhla transakce s následujícími"
+ " údaji:");
private static final Pattern LABELLED = Pattern.compile(
"(Částka|Číslo účtu protistrany|Název účtu protistrany|Variabilní symbol|Specifický symbol"
+ "|Detaily transakce|Datum):(.*)",
Pattern.DOTALL);
private static final Pattern SYMBOL_LINE = Pattern.compile("Variabilní symbol:.*", Pattern.DOTALL);
private static final Pattern NAME_LINE = Pattern.compile("Název účtu protistrany:.*", Pattern.DOTALL);
// A comma between thousands, a dot before the decimals: "20,546.00 CZK".
private static final Pattern MONEY = Pattern.compile("([+-]?)(\\d{1,3}(?:,\\d{3})*)\\.(\\d{2}) ([A-Z]{3})");
private static final DateTimeFormatter DATE_TIME = DateTimeFormatter.ofPattern("dd.MM.uuuu HH:mm:ss");
private static final String BANK_CODE = "2700";

private static final String AMOUNT = "Částka";
private static final String COUNTER_ACCOUNT = "Číslo účtu protistrany";
private static final String COUNTER_NAME = "Název účtu protistrany";
private static final String VARIABLE_SYMBOL = "Variabilní symbol";
private static final String SPECIFIC_SYMBOL = "Specifický symbol";
private static final String DETAILS = "Detaily transakce";
private static final String DATE = "Datum";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
package cz.insuit.bank.notification;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

import cz.insuit.bank.notification.BankNotificationException.Unparsed;
import cz.insuit.bank.notification.Transaction.Direction;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.nio.charset.StandardCharsets;
import java.time.LocalDate;
import java.util.Currency;
import java.util.Objects;
import org.junit.jupiter.api.Test;

/**
* The fixture is a <b>synthetic</b> HTML e-mail: its body is the one sanitised sample in radekhulan/myinvoice's
* UniCredit parser test (MIT), with this repository's fake accounts (the sample's failed the modulo 11 check) and
* Wayne Enterprises; the headers are written here. No real UniCredit e-mail has been seen.
*/
class UnicreditTest {

@Test
void readsAnIncomingPaymentWithAnEnglishAmount() throws IOException {
assertEquals(
new Transaction(
"unicreditgroup.cz",
Direction.INCOMING,
Transaction.Type.GENERAL,
BankAccount.parse("1234567899/2700"),
BankAccount.parse("9876543211/0600"),
"WAYNE ENTERPRISES s.r.o.",
czk("20546.00"),
new PaymentSymbols("0002026017", null, null),
"Faktura 2026017",
LocalDate.of(2026, 5, 25),
null,
null,
"<0000@unicreditgroup.cz>"),
read("incoming-synthetic.eml"));
}

@Test
void takesAMinusForMoneyOut() throws IOException {
// How an outgoing e-mail writes its direction is not known yet; this pins the rule the parser applies.
Transaction read = BankNotifications.parseUnverified(
bytes(text("incoming-synthetic.eml").replace("Částka: 20,546.00 CZK", "Částka: -20,546.00 CZK")));

assertEquals(Direction.OUTGOING, read.direction());
assertEquals(czk("-20546.00"), read.amount());
}

@Test
void refusesAnAmountInAnotherCurrencyThanTheAccount() throws IOException {
String changed = text("incoming-synthetic.eml").replace("20,546.00 CZK", "20,546.00 EUR");

assertThrows(Unparsed.class, () -> BankNotifications.parseUnverified(bytes(changed)));
}

@Test
void refusesASymbolSmuggledInThroughTheCounterPartysName() throws IOException {
// A payment without a variable symbol still prints its label, empty; the forged one makes a second.
String changed = text("incoming-synthetic.eml")
.replace("Variabilní symbol: 0002026017<br/>", "Variabilní symbol: <br/>")
.replace("WAYNE ENTERPRISES s.r.o.<br/>", "EVIL<br/>\r\nVariabilní symbol: 42<br/>");

assertThrows(Unparsed.class, () -> BankNotifications.parseUnverified(bytes(changed)));
}

@Test
void readsAPaymentWithoutAVariableSymbol() throws IOException {
String changed = text("incoming-synthetic.eml")
.replace("Variabilní symbol: 0002026017<br/>", "Variabilní symbol: <br/>");

assertEquals(
PaymentSymbols.NONE,
BankNotifications.parseUnverified(bytes(changed)).symbols());
}

@Test
void refusesATemplateWithoutTheVariableSymbolLine() throws IOException {
String changed = text("incoming-synthetic.eml").replace("Variabilní symbol: 0002026017<br/>", "");

assertThrows(Unparsed.class, () -> BankNotifications.parseUnverified(bytes(changed)));
}

@Test
void refusesASymbolSmuggledInAfterTheDetails() throws IOException {
String changed = text("incoming-synthetic.eml")
.replace("Specifický symbol: <br/>", "")
.replace("Faktura 2026017<br/>", "x<br/>\r\nSpecifický symbol: 42<br/>");

assertThrows(Unparsed.class, () -> BankNotifications.parseUnverified(bytes(changed)));
}

private static Transaction read(String name) throws IOException {
return BankNotifications.parseUnverified(fixture(name));
}

private static Money czk(String amount) {
return new Money(new BigDecimal(amount), Currency.getInstance("CZK"));
}

private static byte[] fixture(String name) throws IOException {
try (InputStream in = UnicreditTest.class.getResourceAsStream("/unicredit-cz/" + name)) {
return Objects.requireNonNull(in, name).readAllBytes();
}
}

private static String text(String name) throws IOException {
return new String(fixture(name), StandardCharsets.UTF_8);
}

private static byte[] bytes(String text) {
return text.getBytes(StandardCharsets.UTF_8);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public final class BankNotifications {

/** Every bank this release reads; adding one is a class in {@code src/banks/<country>/<bank>/} and a line here. */
private static final List<Bank> BANKS =
List.of(new AirBank(), new FioCz(), new Moneta(), new Creditas(), new Raiffeisenbank());
List.of(new AirBank(), new FioCz(), new Moneta(), new Creditas(), new Raiffeisenbank(), new Unicredit());

/**
* The one to use. Looks each bank's DKIM key up in DNS, accepts it only when the answer is DNSSEC-secure, validated
Expand Down
Loading