Skip to content

Commit

Permalink
Add option to delete processed mails (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
antedebaas authored Jan 20, 2024
1 parent dfaa93a commit e12ce51
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 3 deletions.
4 changes: 3 additions & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,6 @@ MAILER_DSN=null://null

MAILBOX_CONNECTION=
MAILBOX_USERNAME=
MAILBOX_PASSWORD=
MAILBOX_PASSWORD=

DELETE_PROCESSED_MAILS=
3 changes: 2 additions & 1 deletion .env.test
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ MAILER_DSN=null://null

MAILBOX_CONNECTION="localhost:993/imap/ssl"
MAILBOX_USERNAME="[email protected]"
MAILBOX_PASSWORD="password"
MAILBOX_PASSWORD="password"
DELETE_PROCESSED_MAILS=false
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ ENV MAILER_SMTPPORT=25
ENV MAILER_IMAPPORT=993
ENV MAILER_USER=
ENV MAILER_PASSWORD=
ENV DELETE_PROCESSED_MAILS=

RUN apk --update add ca-certificates
RUN apk --no-cache add \
Expand Down
1 change: 1 addition & 0 deletions config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# https://symfony.com/doc/current/best_practices.html#use-parameters-for-application-configuration
parameters:
app.mailbox_username: '%env(MAILBOX_USERNAME)%'
app.delete_processed_mails: '%env(DELETE_PROCESSED_MAILS)%'

services:
# default configuration for services in *this* file
Expand Down
1 change: 1 addition & 0 deletions dockerfiles/containerstartup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ if [ ! -f "/var/www/html/.env.local" ]; then
echo "MAILBOX_CONNECTION=\"$MAILER_HOST:$MAILER_IMAPPORT/imap/ssl\"" >> /var/www/html/.env.local
echo "MAILBOX_USERNAME=\"$MAILER_USER\"" >> /var/www/html/.env.local
echo "MAILBOX_PASSWORD=\"$MAILER_PASSWORD\"" >> /var/www/html/.env.local
echo "DELETE_PROCESSED_MAILS=\"$DELETE_PROCESSED_MAILS\"" >> /var/www/html/.env.local
fi

echo "Run migrations"
Expand Down
9 changes: 8 additions & 1 deletion src/Command/CheckmailboxCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

use Doctrine\ORM\EntityManagerInterface;
use SecIT\ImapBundle\Service\Imap;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;

use App\Entity\Domains;
use App\Entity\MXRecords;
Expand All @@ -32,11 +33,13 @@ class CheckmailboxCommand extends Command
{
private $em;
private $imap;
private $params;

public function __construct(EntityManagerInterface $em, Imap $imap)
public function __construct(EntityManagerInterface $em, Imap $imap, ParameterBagInterface $params)
{
$this->em = $em;
$this->imap = $imap;
$this->params = $params;
parent::__construct();
}

Expand Down Expand Up @@ -276,6 +279,10 @@ private function open_mailbox(Imap $imap):array
$smtptls_reports = array_merge($smtptls_reports,$new_reports['smtptls_reports']);
unlink($attachment->filePath);
}

if ($this->params->get('app.delete_processed_mails') == "true") {
$mailbox->deleteMail($mailId);
}
}
return array('num_emails' => $num_emails, 'reports' => array('dmarc_reports' => $dmarc_reports, 'smtptls_reports' => $smtptls_reports));
}
Expand Down

0 comments on commit e12ce51

Please sign in to comment.