3

So basically I have been looking for a solution for like two days straight and nothing seems to be helping.

I am using Roundcube mail client with IMAP, postfixadmin and dovecot and whenever I try to upload attachments, I get an internal server error. Here is something I managed to catch in logs:

[11-Nov-2021 01:41:27 UTC] PHP Fatal error:  Uncaught TypeError: fclose(): Argument #1 ($stream) must be of type resource, null given in /var/www/roundcube/program/lib/Roundcube/rcube_imap_generic.php:430
Stack trace:
#0 /var/www/roundcube/program/lib/Roundcube/rcube_imap_generic.php(430): fclose()
#1 /var/www/roundcube/program/lib/Roundcube/rcube_imap_generic.php(1149): rcube_imap_generic->closeSocket()
#2 /var/www/roundcube/program/lib/Roundcube/rcube_imap.php(215): rcube_imap_generic->closeConnection()
#3 /var/www/roundcube/program/lib/Roundcube/rcube.php(1038): rcube_imap->close()
#4 /var/www/roundcube/program/include/rcmail.php(921): rcube->shutdown()
#5 [internal function]: rcmail->shutdown()
#6 {main}
  thrown in /var/www/roundcube/program/lib/Roundcube/rcube_imap_generic.php on line 430

There are a lot of settings all around the server so if you think that you need some of them for debugging, just ask and I'll happily put them here

EDIT: I made a quick video with all the things going on. You can see that upload "failed" with internal server error message, but after refreshing the page, attachment is there and it's being sent with email, and after receiving that email, I can't see attachment preview in email, but when I click on it I can see it and download it. Demo

Matej Petric
  • 108
  • 10
  • So the problem only occurs in roundcube webmail ? – Ken Lee Nov 11 '21 at 02:34
  • Yeah, only when trying to upload attachment. Funny thing is that, even tho I get internal server error when trying to upload attachemnt, it’s still being sent with email and I can see it when composing email if I refresh the page after upload. Also, I tried to send email to myself with attachment and I receive it but I get internal server error once I open that received email, but I can still download attachment and then open it normally, so it looks like some problem with displaying attachments. – Matej Petric Nov 11 '21 at 06:54
  • Temp folder, where attachments are stored, have 777 permissions on it, and is owned by www-data user, so it shouldn’t be a permissions issue – Matej Petric Nov 11 '21 at 21:45

1 Answers1

3

After a few long days, I finally managed to figure this out on my own, and it's really simple. So what's happening is that rounducbe is trying to close file that doesn't exist.

So, to all of you who are facing with the same problem, to fix this you have to edit file "path/to/roundcube/program/lib/Roundcube/rcube_imap_generic.php" on line 430 Change this:

protected function closeSocket()
    {
        @fclose($this->fp);
        $this->fp = null;
    }

Into this:

protected function closeSocket()
    {
        if($this->fp){
        @fclose($this->fp);
        }
        $this->fp = null;
    }
Matej Petric
  • 108
  • 10