Author Topic: managesieve plugin fail with dbmail-timsieved  (Read 11680 times)

Offline chingson

  • Newbie
  • *
  • Posts: 3
managesieve plugin fail with dbmail-timsieved
« on: November 24, 2011, 02:28:01 AM »
After R-Cube 5, Managesieve plug-in always fail with my DBMAIL-timsieved, which shall be compatible to other sieve-daemon. Even all my scripts are created by R-Cube 4.

I found modifying _recvLn() function in Sieve.php can make it back to work. I don't know why empty $lastline need to raise error in source code.

Any comments?

    function _recvLn()
    {
        if (PEAR::isError($lastline = $this->_sock->gets(8192))) {
            return PEAR::raiseError(
                'Failed to read from socket: ' . $lastline->getMessage()
            );
        }

        $lastline = rtrim($lastline);
        $this->_debug("S: $lastline");

        //if ($lastline === '') {
         //   return PEAR::raiseError('Failed to read from socket');
        //}

        return $lastline;
    }

Offline alec

  • Hero Member
  • *****
  • Posts: 1,363
managesieve plugin fail with dbmail-timsieved
« Reply #1 on: November 24, 2011, 04:19:07 AM »
Please enable managesieve_debug option and privide the log.

Offline chingson

  • Newbie
  • *
  • Posts: 3
sieve log file and errors
« Reply #2 on: November 24, 2011, 05:17:11 AM »
as the attached documents.

Offline alec

  • Hero Member
  • *****
  • Posts: 1,363
managesieve plugin fail with dbmail-timsieved
« Reply #3 on: November 24, 2011, 06:20:30 AM »
It looks that DBMail uses Cyrus' timsieved implementation. So, it can have the same bug for which there's already a workaround in Net_Sieve package. Please revert your changes and try with this patch (plugins/managesieve/lib/Net/Sieve.php):
Code: [Select]
--- Sieve.php   (wersja 5478)
+++ Sieve.php   (kopia robocza)
@@ -1186,7 +1186,7 @@
         // The server should be sending a CAPABILITY response after
         // negotiating TLS. Read it, and ignore if it doesn't.
         // Doesn't work with older timsieved versions
-        $regexp = '/^CYRUS TIMSIEVED V([0-9.]+)/';
+        $regexp = '/TIMSIEVED V*([0-9.]+)/i';
         if (!preg_match($regexp, $this->_capability['implementation'], $matches)
             || version_compare($matches[1], '2.3.10', '>=')
         ) {

Offline chingson

  • Newbie
  • *
  • Posts: 3
Still fail when read empty line
« Reply #4 on: November 24, 2011, 06:57:55 PM »
I tried but it still fail at _recvLn() when read empty.
The sieve log shows that it is dead at the tail of sieve script reading.

Quote from: alec;37418
It looks that DBMail uses Cyrus' timsieved implementation. So, it can have the same bug for which there's already a workaround in Net_Sieve package. Please revert your changes and try with this patch (plugins/managesieve/lib/Net/Sieve.php):
Code: [Select]

--- Sieve.php   (wersja 5478)
+++ Sieve.php   (kopia robocza)
@@ -1186,7 +1186,7 @@
         // The server should be sending a CAPABILITY response after
         // negotiating TLS. Read it, and ignore if it doesn't.
         // Doesn't work with older timsieved versions
-        $regexp = '/^CYRUS TIMSIEVED V([0-9.]+)/';
+        $regexp = '/TIMSIEVED V*([0-9.]+)/i';
         if (!preg_match($regexp, $this->_capability['implementation'], $matches)
             || version_compare($matches[1], '2.3.10', '>=')
         ) {

Offline alec

  • Hero Member
  • *****
  • Posts: 1,363
managesieve plugin fail with dbmail-timsieved
« Reply #5 on: November 25, 2011, 02:53:12 AM »
I've opened a ticket in PEAR's bugtracker. Let's continue there. Please, attach debug log when your Sieve.php file is not patched.

Offline pegasus

  • Newbie
  • *
  • Posts: 2
managesieve plugin fail with dbmail-timsieved
« Reply #6 on: March 15, 2012, 12:49:37 PM »
I have another problem with managesieve connecting to dbmail sieve.

Here's the protocol log I get:

S: "IMPLEMENTATION" "DBMail timsieved 3.0.0-rc3"
S: "SASL" "PLAIN"
S: "SIEVE" "regex imap4flags relational subaddress fileinto reject envelope vacation notify "
S: OK
C: CAPABILITY
S: "IMPLEMENTATION" "DBMail timsieved 3.0.0-rc3"
S: "SASL" "PLAIN"
S: "SIEVE" "regex imap4flags relational subaddress fileinto reject envelope vacation notify "
S: OK
C: AUTHENTICATE "PLAIN" "blah"
S: OK
C: LISTSCRIPTS
S: "sieve" ACTIVE
S: OK
C: GETSCRIPT "sieve"
S: {18+}
S: /* empty script */
S: OK

At this point, execution hangs and php times out after 120s. I have xdebug and here's the stactrace I get:

PHP Fatal error:  Maximum execution time of 120 seconds exceeded in /var/www/roundcubemail-0.7.2/plugins/managesieve/lib/rcube_sieve_script.php on line 945
PHP Stack trace:
PHP   1. {main}() /var/www/roundcubemail-0.7.2/index.php:0
PHP   2. rcube_plugin_api->exec_action() /var/www/roundcubemail-0.7.2/index.php:248
PHP   3. call_user_func() /var/www/roundcubemail-0.7.2/program/include/rcube_plugin_api.php:296
PHP   4. managesieve->managesieve_actions() /var/www/roundcubemail-0.7.2/program/include/rcube_plugin_api.php:296
PHP   5. managesieve->managesieve_start() /var/www/roundcubemail-0.7.2/plugins/managesieve/managesieve.php:309
PHP   6. rcube_sieve->load() /var/www/roundcubemail-0.7.2/plugins/managesieve/managesieve.php:269
PHP   7. rcube_sieve->_parse() /var/www/roundcubemail-0.7.2/plugins/managesieve/lib/rcube_sieve.php:288
PHP   8. rcube_sieve_script->__construct() /var/www/roundcubemail-0.7.2/plugins/managesieve/lib/rcube_sieve.php:313
PHP   9. rcube_sieve_script->_parse_text() /var/www/roundcubemail-0.7.2/plugins/managesieve/lib/rcube_sieve_script.php:70
PHP  10. rcube_sieve_script->_parse_actions() /var/www/roundcubemail-0.7.2/plugins/managesieve/lib/rcube_sieve_script.php:527
PHP  11. rcube_sieve_script::tokenize() /var/www/roundcubemail-0.7.2/plugins/managesieve/lib/rcube_sieve_script.php:736

To me looks like tokenize gets stuck parsing the "/* empty script */" that gets inserted by default by managesieve if no script exists. This seems so silly that I hope I don't understand this stack trace properly.

Can you help me with this?

PHP is 5.3.10.
« Last Edit: March 15, 2012, 12:51:45 PM by pegasus »

Offline alec

  • Hero Member
  • *****
  • Posts: 1,363
managesieve plugin fail with dbmail-timsieved
« Reply #7 on: March 15, 2012, 03:02:07 PM »
Quote from: pegasus;38416

C: GETSCRIPT "sieve"
S: {18+}
S: /* empty script */
S: OK


"/* empty script */" works for me. What I see here wrong is "{18+}" in server response. It should be "{18}", but this might be not the issue.

Offline alec

  • Hero Member
  • *****
  • Posts: 1,363
managesieve plugin fail with dbmail-timsieved
« Reply #8 on: March 15, 2012, 03:07:40 PM »
After some tests I can confirm this is related to "{18+}". You should request a bug to DBMail developers. I'll try to find a workaround tomorrow.

Offline alec

  • Hero Member
  • *****
  • Posts: 1,363

Offline pegasus

  • Newbie
  • *
  • Posts: 2
managesieve plugin fail with dbmail-timsieved
« Reply #10 on: March 16, 2012, 05:55:29 AM »
Confirmed, working. Thanks.