A professional PHP library for processing bank confirmation emails from Slovak and Czech banks. Extract transaction details, account numbers, amounts, and symbols automatically from bank notification emails.
| Bank | Country | Parsers | Email Formats | Features |
|---|---|---|---|---|
| TatraBanka | πΈπ° Slovakia | 3 parsers | Plain text, ComfortPay, PGP encrypted | Multi-format support, PGP decryption |
| ΔSOB CZ | π¨πΏ Czech Republic | 1 parser | Multi-transaction HTML | Batch processing |
| ΔSOB SK | πΈπ° Slovakia | 1 parser | Multi-transaction HTML | Batch processing |
| VUB | πΈπ° Slovakia | 1 parser | Plain text | Simple format |
- π§ Multiple email formats: Plain text, HTML, PGP encrypted
- π° Financial data extraction: Amounts, currencies, account numbers
- π’ Banking symbols: Variable Symbol (VS), Constant Symbol (KS), Specific Symbol (SS)
- π PGP decryption: Handle encrypted bank statements
- π Multi-transaction support: Process emails with multiple payments
- π‘οΈ Type safety: Full PHP 8.2+ strict typing
- β Well tested: 95%+ code coverage with comprehensive test suite
- PHP 8.2+ (PHP 8.3, 8.4 recommended)
- Composer for installation
composer require tomaj/bank-mails-parserUpgrading from 3.x? See the 4.0 Upgrade Guide for breaking changes and migration steps.
<?php
use Tomaj\BankMailsParser\Parser\TatraBanka\TatraBankaMailParser;
// Initialize parser
$parser = new TatraBankaMailParser();
// Parse bank email content
$mailContent = $parser->parse($emailBodyContent);
// Extract transaction details
if ($mailContent) {
echo "Amount: " . $mailContent->getAmount() . " " . $mailContent->getCurrency() . "\n";
echo "Variable Symbol: " . $mailContent->getVs() . "\n";
echo "Account: " . $mailContent->getAccountNumber() . "\n";
}| PHP Version | Library Version | Status |
|---|---|---|
| 8.4 | 4.0+ | β Fully supported |
| 8.3 | 4.0+ | β Fully supported |
| 8.2 | 4.0+ | β Fully supported |
| 8.1 | 3.0 only | |
| 7.4 | 3.0 only |
VΓ‘Ε‘ zostatok po transakcii je 1234.56 EUR
Suma: 50.00 EUR
VS: 1234567890
KS: 0308
SS: 123
<tr>
<td>15.12.2023</td>
<td>+1,234.50 CZK</td>
<td>CZ1234567890</td>
<td>VS: 987654321</td>
</tr>Dtum: 11.12.2019
Suma: 34,90
Z tu: SK4502000000001123100000
VS: 9911929700
KS: 0308
Basic usage with TatraBanka parser:
use Tomaj\BankMailsParser\Parser\TatraBanka\TatraBankaMailParser;
$tatraBankaMailParser = new TatraBankaMailParser();
$mailContent = $tatraBankaMailParser->parse('mail content');
echo $mailContent->getKs() . "\n";
echo $mailContent->getSs() . "\n";
echo $mailContent->getVs() . "\n";
echo $mailContent->getReceiverMessage() . "\n";
echo $mailContent->getDescription() . "\n";
echo $mailContent->getCurrency() . "\n";
echo $mailContent->getTransactionDate() . "\n";
echo $mailContent->getAccountNumber() . "\n";
echo $mailContent->getAmount() . "\n";
echo $mailContent->getAccountNumber() . "\n";
echo $mailContent->getTxn() . "\n";With TatraBankaSimpleMailParser you can parse comforpay emails. There are other getters like CID for reccurent payments.
echo $mailContent->getCid() . "\n";
echo $mailContent->getSign() . "\n";
echo $mailContent->getRes() . "\n";With TatraBankaStatementMailParser you can parse encrypted PGP emails containing payment statements:
use Tomaj\BankMailsParser\Parser\TatraBanka\TatraBankaStatementMailParser;
use Tomaj\BankMailsParser\Parser\TatraBanka\TatraBankaMailDecryptor;
$decryptor = new TatraBankaMailDecryptor('/path/to/private-key.asc', 'passphrase');
$parser = new TatraBankaStatementMailParser($decryptor);
$mailContents = $parser->parseMulti('encrypted mail content');
foreach ($mailContents as $mailContent) {
echo $mailContent->getVs() . "\n";
echo $mailContent->getAmount() . "\n";
echo $mailContent->getCurrency() . "\n";
}For Czech ΔSOB emails:
use Tomaj\BankMailsParser\Parser\Csob\CsobMailParser;
$csobMailParser = new CsobMailParser();
$mailContents = $csobMailParser->parseMulti('mail content');
foreach ($mailContents as $mailContent) {
echo $mailContent->getVs() . "\n";
echo $mailContent->getKs() . "\n";
echo $mailContent->getAmount() . "\n";
echo $mailContent->getCurrency() . "\n";
echo $mailContent->getAccountNumber() . "\n";
echo $mailContent->getSourceAccountNumber() . "\n";
}For Slovak ΔSOB emails:
use Tomaj\BankMailsParser\Parser\Csob\SkCsobMailParser;
$skCsobMailParser = new SkCsobMailParser();
$mailContents = $skCsobMailParser->parseMulti('mail content');
foreach ($mailContents as $mailContent) {
echo $mailContent->getVs() . "\n";
echo $mailContent->getKs() . "\n";
echo $mailContent->getAmount() . "\n";
echo $mailContent->getCurrency() . "\n";
echo $mailContent->getAccountNumber() . "\n";
}For VUB bank emails:
use Tomaj\BankMailsParser\Parser\Vub\VubMailParser;
$vubMailParser = new VubMailParser();
$mailContent = $vubMailParser->parse('mail content');
echo $mailContent->getVs() . "\n";
echo $mailContent->getKs() . "\n";
echo $mailContent->getAmount() . "\n";
echo $mailContent->getAccountNumber() . "\n";
echo $mailContent->getTransactionDate() . "\n";The MailContent object provides access to all extracted transaction data:
// Financial data
$mailContent->getAmount(): ?float // Transaction amount
$mailContent->getCurrency(): ?string // Currency code (EUR, CZK, etc.)
$mailContent->getTransactionDate(): ?int // Unix timestamp of transaction
// Account information
$mailContent->getAccountNumber(): ?string // Destination account
$mailContent->getSourceAccountNumber(): ?string // Source account (if available)
// Banking symbols
$mailContent->getVs(): ?string // Variable Symbol
$mailContent->getKs(): ?string // Constant Symbol
$mailContent->getSs(): ?string // Specific Symbol
// Additional data
$mailContent->getReceiverMessage(): ?string // Payment message
$mailContent->getDescription(): ?string // Transaction description
$mailContent->getTxn(): ?string // Transaction ID$mailContent->getCid(): ?string // ComfortPay Client ID
$mailContent->getSign(): ?string // HMAC signature
$mailContent->getRes(): ?string // Result code
$mailContent->getRc(): ?string // Return code$parser = new TatraBankaMailParser();
$result = $parser->parse($emailContent);
if ($result === null) {
// Email format not recognized or parsing failed
echo "Unable to parse email content";
} else {
// Successfully parsed - $result is MailContent object
echo "Amount: " . ($result->getAmount() ?? 'N/A');
}- Unknown email format: Parser returns
null - Partial data: Some MailContent getters may return
null - Invalid amounts: Non-numeric values are handled gracefully
- Date parsing failures: Invalid dates result in
nulltimestamp
function validateTransaction(MailContent $content): bool {
return $content->getAmount() !== null
&& $content->getAmount() > 0
&& $content->getVs() !== null
&& strlen($content->getVs()) > 0;
}- PHP 8.2+ required (dropped PHP 7.4, 8.0, 8.1 support)
- PHPUnit 11 for development (if extending library)
β Non-breaking Changes:
- All existing parser APIs remain unchanged
- Same method signatures and return types
- Improved test coverage and GitHub Pages reporting
# Update your composer.json
composer require tomaj/bank-mails-parser:^4.0- PHP 7.4+ required (dropped PHP 7.1, 7.2, 7.3)
- ParserInterface changes: Returns
?MailContentinstead offalse - Strict types: Added
declare(strict_types=1)throughout codebase - Namespace changes: TatraBanka parsers moved to
\TatraBankasubfolder
Migration Steps:
// Before (v2.x)
if ($parser->parse($content) === false) {
// Handle parsing failure
}
// After (v3.x)
if ($parser->parse($content) === null) {
// Handle parsing failure
}- Parser now returns
MailContentfor both successful and failed bank responses - In v1.x, parser returned
MailContentonly for successful transactions
π‘ See full changelog: CHANGELOG.md
Example how to use with imap mail downloader:
use Tomaj\ImapMailDownloader\Downloader;
use Tomaj\ImapMailDownloader\MailCriteria;
use Tomaj\ImapMailDownloader\Email;
use Tomaj\BankMailsParser\Parser\TatraBanka\TatraBankaMailParser;
$downloader = new Downloader('*imap host*', *port*, '*username*', '*password*');
$criteria = new MailCriteria();
$criteria->setFrom('some@email.com');
$downloader->fetch($criteria, function(Email $email) {
$tatraBankaMailParser = new TatraBankaMailParser();
$mailContent = $tatraBankaMailParser->parse($email->getBody());
// process $mailContent data...
return true;
});Note: You have to include package imap-email-downloader: composer require tomaj/imap-email-downloader
- Store PGP keys outside web root
- Use environment variables for sensitive configuration
- Log parsing failures for security monitoring
- Validate all extracted amounts before processing payments
- Never expose raw email content in error messages
We welcome contributions! Here's how you can help:
- Fork the repository and create feature branch
- Study existing parsers in
src/Parser/for patterns - Create parser class implementing
ParserInterface:namespace Tomaj\BankMailsParser\Parser\YourBank; class YourBankMailParser implements ParserInterface { public function parse(string $content): ?MailContent { /* ... */ } }
- Add comprehensive tests in
tests/Parser/YourBank/ - Update documentation - README, CHANGELOG
- Submit Pull Request with example email formats
git clone https://github.com/tomaj/bank-mails-parser.git
cd bank-mails-parser
composer install
./vendor/bin/phpunit # Run tests
./vendor/bin/phpstan analyse # Static analysis- PHP 8.2+ with strict types
- PSR-12 coding standard
- 100% test coverage for new parsers
- Comprehensive PHPDoc comments
- Must handle both successful and failed transactions
- Support for multi-transaction emails (if applicable)
- Robust regex patterns with proper escaping
- Currency and amount parsing with locale support
π‘ Need help? Open an issue or check existing parser implementations for guidance!