liuch / dmarc-srg

A php parser, viewer and summary report generator for incoming DMARC reports.
GNU General Public License v3.0
223 stars 33 forks source link

Error: Undefined constant (PHP 8.2.4) #82

Closed mbsouth closed 1 year ago

mbsouth commented 1 year ago

Release: dmarc-srg master OS: Windows 10 PHP: 8.2.4

When reading the reports (IMAP) and cleaning the mailbox, I get the following errors:

[...]\web\dmarc>php utils\fetch_reports.php
dmarc-srg [error]: Error: Undefined constant "Liuch\DmarcSrg\Sources\SORTDATE" in [...]\web\dmarc\classes\Sources\MailboxSource.php:122
Stack trace:
#0 [...]\web\dmarc\classes\Report\ReportFetcher.php(69): Liuch\DmarcSrg\Sources\MailboxSource->rewind()
#1 [...]\web\dmarc\utils\fetch_reports.php(150): Liuch\DmarcSrg\Report\ReportFetcher->fetch()
#2 {main}
Error: Undefined constant "Liuch\DmarcSrg\Sources\SORTDATE" (0)

[...]\web\dmarc>php utils\mailbox_cleaner.php
dmarc-srg [error]: Error: Undefined constant "Liuch\DmarcSrg\SORTDATE" in [...]\web\dmarc\utils\mailbox_cleaner.php:128
Stack trace:
#0 {main}
Error: Undefined constant "Liuch\DmarcSrg\SORTDATE" (0)

I searched the code; the constant SORTDATE is not defined but is used as a parameter in two functions.

williamdes commented 1 year ago

Hi You are missing the PHP imap extension: https://www.php.net/manual/en/function.imap-sort.php It defines SORTDATE

mbsouth commented 1 year ago

@williamdes

Hi! Got it. You are right: PHP imap extension wasn´t enabled.

Sorry for this post. No bug, everything works perfect!

williamdes commented 1 year ago

@liuch the main entrypoint should check for the extension and stop execution directly Can you add this?

liuch commented 1 year ago

check_config.php must catch that and warn. You suggest to add an extra check to fetch_reports.php, right?

williamdes commented 1 year ago

check_config.php must catch that and warn. You suggest to add an extra check to fetch_reports.php, right?

I think we should have like most normal php projects a file that has only the autoload code from https://github.com/liuch/dmarc-srg/blob/master/init.php

create a class with static functions and move the left over code into it and then re-use the init code on all entrypoints/files to ensure we check and init everything the same way

By the way, dmarc-srg is so light, I could package it into Debian ! But only if the change for the autload is made. See: https://salsa.debian.org/phpmyadmin-team/phpmyadmin/-/blob/debian/bullseye/debian/rules?ref_type=heads#L32-37

Basically to be packaged into Debian for this project: