-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
HorstOeko
committed
Oct 26, 2024
1 parent
4be9d3e
commit 02c75dd
Showing
4 changed files
with
83 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
MAIL_HOST=127.0.0.1 | ||
MAIL_PORT=993 | ||
MAIL_PROTOCOL=imap | ||
MAIL_ENCRYPTION=ssl | ||
MAIL_VALIDATECERT=true | ||
MAIL_USER=demouser | ||
MAIL_PASSWORD=demopassword | ||
MAIL_FOLDERS=INBOX | ||
MAIL_MIMETYPES=text/xml,application/pdf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
use Dotenv\Dotenv; | ||
use Dotenv\Exception\InvalidEncodingException; | ||
use Dotenv\Exception\InvalidFileException; | ||
use Dotenv\Exception\ValidationException; | ||
use horstoeko\zugferdmail\config\ZugferdMailAccount; | ||
use horstoeko\zugferdmail\config\ZugferdMailConfig; | ||
|
||
class ExampleHelper | ||
{ | ||
/** | ||
* Create a mail account from a .env file | ||
* | ||
* @param ZugferdMailConfig $config | ||
* @return ZugferdMailAccount | ||
* @throws RuntimeException | ||
* @throws InvalidEncodingException | ||
* @throws InvalidFileException | ||
* @throws ValidationException | ||
* @throws InvalidArgumentException | ||
*/ | ||
public static function createMailAccountFromDotEnv(ZugferdMailConfig $config): ZugferdMailAccount | ||
{ | ||
$dotEnv = Dotenv::createImmutable(dirname(__FILE__)); | ||
$dotEnv->safeLoad(); | ||
$dotEnv->required('MAIL_PORT')->isInteger(); | ||
$dotEnv->required('MAIL_VALIDATECERT')->isBoolean(); | ||
|
||
$mailAccount = $config->addAccount( | ||
'myaccount-1', | ||
$_ENV['MAIL_HOST'], | ||
filter_var($_ENV['MAIL_PORT'], FILTER_VALIDATE_INT), | ||
$_ENV['MAIL_PROTOCOL'], | ||
$_ENV['MAIL_ENCRYPTION'], | ||
filter_var($_ENV['MAIL_VALIDATECERT'], FILTER_VALIDATE_BOOLEAN), | ||
$_ENV['MAIL_USER'], | ||
$_ENV['MAIL_PASSWORD'] | ||
); | ||
|
||
$mailAccount->setFoldersToWatch(explode(",", $_ENV['MAIL_FOLDERS'])); | ||
$mailAccount->setMimeTypesToWatch(explode(",", $_ENV['MAIL_MIMETYPES'])); | ||
|
||
return $mailAccount; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
use Webklex\PHPIMAP\Folder; | ||
use Webklex\PHPIMAP\Message; | ||
use Webklex\PHPIMAP\Attachment; | ||
use horstoeko\zugferd\ZugferdDocumentReader; | ||
use horstoeko\zugferdmail\ZugferdMailReader; | ||
use horstoeko\zugferdmail\config\ZugferdMailConfig; | ||
use horstoeko\zugferdmail\config\ZugferdMailAccount; | ||
use horstoeko\zugferdmail\handlers\ZugferdMailHandlerSaveToFile; | ||
|
||
require_once dirname(__FILE__) . "/../vendor/autoload.php"; | ||
require_once dirname(__FILE__) . '/ExampleHelper.php'; | ||
|
||
$config = new ZugferdMailConfig(); | ||
|
||
$account = ExampleHelper::createMailAccountFromDotEnv($config); | ||
|
||
$account->addHandler(new ZugferdMailHandlerSaveToFile('/tmp', 'file.xml')); | ||
|
||
$account->addCallback(function (ZugferdMailAccount $account, Folder $folder, Message $message, Attachment $attachment, ZugferdDocumentReader $document, int $recognitionType) { | ||
$document->getDocumentInformation($documentno, $documenttypecode, $documentdate, $invoiceCurrency, $taxCurrency, $documentname, $documentlanguage, $effectiveSpecifiedPeriod); | ||
echo "Document found ... " . PHP_EOL; | ||
echo "Document No. ..... " . $documentno . PHP_EOL; | ||
}); | ||
|
||
$reader = new ZugferdMailReader($config); | ||
$reader->checkAllAccounts(); |