phpubuntuimapdovecotroundcube

Roundcube attachment upload internal server error


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


Solution

  • 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;
        }