Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use of undefined constant FT_UID - assumed 'FT_UID #2604

Closed
Vityas1 opened this issue Jan 23, 2023 · 16 comments
Closed

Use of undefined constant FT_UID - assumed 'FT_UID #2604

Vityas1 opened this issue Jan 23, 2023 · 16 comments

Comments

@Vityas1
Copy link

Vityas1 commented Jan 23, 2023

I completed freescout setup and config mailbox on my VPS. When trying to send email to this mailbox, it's not working, email never reaches its destination. The same problem is with downloading email. I see in logs this error. There is the same error every minute. Any idea how could it be solved?

Undefined constant "FT_UID" {"exception":"[object] (Symfony\Component\Debug\Exception\FatalThrowableError(code: 0): Undefined constant "FT_UID" at /var/www/user2131/data/www/lr.it-crowd.com/vendor/webklex/laravel-imap/src/config/imap.php:105)
[stacktrace]
#0 /var/www/user2131/data/www/lr.it-crowd.com/vendor/webklex/laravel-imap/src/IMAP/Providers/LaravelServiceProvider.php(66): require()
#1 /var/www/user2131/data/www/lr.it-crowd.com/vendor/webklex/laravel-imap/src/IMAP/Providers/LaravelServiceProvider.php(51): Webklex\IMAP\Providers\LaravelServiceProvider->setVendorConfig()
#2 /var/www/user2131/data/www/lr.it-crowd.com/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(586): Webklex\IMAP\Providers\LaravelServiceProvider->register()
#3 /var/www/user2131/data/www/lr.it-crowd.com/overrides/laravel/framework/src/Illuminate/Foundation/ProviderRepository.php(89): Illuminate\Foundation\Application->register(Object(Webklex\IMAP\Providers\LaravelServiceProvider))
#4 /var/www/user2131/data/www/lr.it-crowd.com/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(561): Illuminate\Foundation\ProviderRepository->load(Array)
#5 /var/www/user2131/data/www/lr.it-crowd.com/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/RegisterProviders.php(17): Illuminate\Foundation\Application->registerConfiguredProviders()
#6 /var/www/user2131/data/www/lr.it-crowd.com/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(213): Illuminate\Foundation\Bootstrap\RegisterProviders->bootstrap(Object(Illuminate\Foundation\Application))
#7 /var/www/user2131/data/www/lr.it-crowd.com/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(296): Illuminate\Foundation\Application->bootstrapWith(Array)
#8 /var/www/user2131/data/www/lr.it-crowd.com/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(119): Illuminate\Foundation\Console\Kernel->bootstrap()
#9 /var/www/user2131/data/www/lr.it-crowd.com/artisan(62): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#10 {main}
"}

@Vityas1
Copy link
Author

Vityas1 commented Jan 23, 2023

imap already enabled
php

@freescout-helpdesk
Copy link
Contributor

freescout-helpdesk commented Jan 23, 2023

Make sure it's also enabled in the console version of PHP: https://github.com/freescout-helpdesk/freescout/wiki/Installation-Guide#9-configuring-cron-jobs (artisan freescout:check-requriements)

@cluster15
Copy link

Sorry, to re-open it. The php-imap c-client becomes more and more difficult to adapt to recent versions of the required libs (e.g. ssl). The software is not maintained for years (better a decade) now, and my provider is not willing to support this anymore. So I activated the new fetching library in .env via:

#### test for new fetching library (not using c-client) APP_NEW_FETCHING_LIBRARY=true

and I get the above error when the imap-c-client is not installed.

The reason is, that the version of webklex/laravel-imap used in freescout implicitly still depends on a loaded c-client for imap (which seems to provide FT_UID). It looks quite like the file webklex/laravel-imap/src/config/imap.php, which throws the error, is version 1.3.0 (commit a5c09cd from 5 1/2 years ago). php artisan fails with Use of undefined constant FT_UID - assumed 'FT_UID' (this will throw an Error in a future version of PHP) with php7.4 already, when the imap-c-client is not installed. And it definitely fails under php8.x, since undefined constants are not only deprecated but not allowed anymore. Under PHP8 even the web-installer fails - or to be more precise it just shows an empty page without any error message - when the imap-c-client is not available with the exact same error.

To sum it up: The error (Use of undefined constant FT_UID - assumed 'FT_UID' ) is caused by the use of an too old version of webklex/laravel-imap/ which implicitly relies on imap-c-client to provide FT_UID. When replacing

'fetch' => FT_UID,

by

'fetch' => \Webklex\PHPIMAP\IMAP::FT_UID,

in vendors/weblex/laravel-imap/src/config/imap.php (at line 105), the new library seems to do the job it is supposed to do. I admit I do not have any module installed that uses the IMAP connection heavily, to judge whether any side effects might exist. A more recent imap implementation by webklex could be the way to go.

And btw the web-installer requires imap-c-client and would not let you install under php8 without it even with the above fix in imap.php. Eventually I succeeded installing freescout from scratch by commenting out the IMAP requirement in config/installer.php beforehand. However I had to manually add APP_NEW_FETCHING_LIBRARY=true to .env and clear the cache, to get freescout running. This is somewhat hackish and could be improved by providing the possibility to use the new library as an option, when the imap-c-client is not available and adding APP_NEW_FETCHING_LIBRARY=true to .env automatically when necessary.

@freescout-helpdesk
Copy link
Contributor

freescout-helpdesk commented Jan 11, 2024

and my provider is not willing to support this anymore

Do you mean you can't enable PHP IMAP extension (https://www.php.net/manual/en/book.imap.php) on your hosting?

And btw the web-installer requires imap-c-client and would not let you install under php8

What error do you see in this case?

@cluster15
Copy link

cluster15 commented Jan 11, 2024

and my provider is not willing to support this anymore

Do you mean you can't enable PHP IMAP extension (https://www.php.net/manual/en/book.imap.php) on your hosting?

Exactly. My provider (the university computer center) is not willing to support that piece of software anymore. One argument is, that it gets increasingly out of sync with the current ssl-libs. The official source code at https://github.com/uw-imap/imap was checked in over 6 years ago and never changed since then. The last changes prior to that were probably adaptations to openssl 1.1. Even in https://www.php.net/manual/en/book.imap.php there is a warning that it is not thread safe and does not handle IMAP commands over POP well (the last is irrelevant to freescout)

Some distributions stopped bundling it over the past 1-2 years (I know SuSE did, and I somewhere read that Mint kicked it out as well).

And btw the web-installer requires imap-c-client and would not let you install under php8

What error do you see in this case?

Not an error as such, but when the requirement that IMAP is present is not met, you cannot proceed with the installation. You might call that expected behaviour, but it keeps you from installing freescout using the laravel-imap-library. I had to comment the IMAP requirement out of the config/installer.php list, to get past that point and then manually changed .env.

And as I said the web-installer does not even start without imap-c-client present due to the error above, when you use the latest version unmodified from freescout.net.

@freescout-helpdesk
Copy link
Contributor

It looks like it was specifically SuSE's decision to drop php-imap extension:

We'll just mention that it in the docs.

@cluster15
Copy link

So you are not going to do anything about it - apart from mentioning SuSE's point of view in the docs? Not even introducing the absolutely minor change I suggested for vendor/webklex/laravel-imap/src/config/imap.php (btw last changes 6 years ago)? Without it the web-installer will not work when the php-imap c-client extension is not available.

I am - to put it mildly - surprised.

@freescout-helpdesk
Copy link
Contributor

Yes, we'll keep php-imap extension required and drop this requirement when FreeScout will fully switch to Webklex/php-imap library (https://github.com/freescout-helpdesk/freescout/wiki/FAQ#what-libraries-does-freescout-use-to-connect-via-imap).

@cluster15
Copy link

I was not asking you to drop the php-imap extension requirement but only to modify vendor/webklex/laravel-imap/src/config/imap.php, so that for a start the web-installer even has a chance to show that the php-imap extension is missing at all. Have you tried the web-installer without a php-imap extension present under PHP8.x? It produces an empty page without even a hint what is going wrong.

@freescout-helpdesk
Copy link
Contributor

...only to modify vendor/webklex/laravel-imap/src/config/imap.php, so that for a start the web-installer even has a chance to show that the php-imap extension is missing at all

It should be possible.

@cluster15
Copy link

cluster15 commented Jan 12, 2024

I checked your Fix and it doesn't work on my side under php8, it still causes php to throw an exception for vendor/webklex/laravel-imap/src/config/imap.php, does it work for you (without a php-imap c-client extension)?

@freescout-helpdesk
Copy link
Contributor

@cluster15
Copy link

cluster15 commented Jan 15, 2024

I did, that's why I asked whether it works on your side. The composer running under PHP8 without php-imap extension fails when finally running php artisan with Undefined constant FT_UID. I am not certain what you want to achieve by using FT_UID ?? 1 ? The problem under PHP8 is, that using FT_UID the way you do is almost like a syntax error which the PHP parser trips over - a bit like forgetting a ";" at the end of a statement. FT_UID is not a variable! Thus FT_UID ?? 1 cannot solve the problem at hand because FT_UID cannot be evaluated to anything - unlike $FT_UID, which evaluates to an unset variable and then $FT_UID ?? 1 would evaluate to 1.

I think, the only way to solve the problem without using a later version of laravel-imap (I think at least 1.4.1), is to replace

'fetch' => FT_UID ?? 1,

by

'fetch' => \Webklex\PHPIMAP\IMAP::FT_UID,

in config/imap.php

@cluster15
Copy link

In a test environment, I installed laravel-imap vers. 1.4.1 in vendors/webklex/ and reverting the overrides in composer.json you introduced, it so far works for the use case I have here. Of course, I cannot test all possible side-effect especially with extension modules that use imap.

@freescout-helpdesk
Copy link
Contributor

It should be fixed now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants