Files
roundcubemail/plugins/reconnect/reconnect.php
Michael Voříšek 6a53a1d853 Fix CS (whitespace, visibility) (#9297)
* Fix "method_argument_space"

* Fix "control_structure_continuation_position"

* Fix "new_with_parentheses"

* Fix "blank_line_before_statement"

* Fix "visibility_required"

* Fix some "array_indentation"

* Fix some "array_indentation" - unify all "rcube::raise_error" calls

* rm useless eslint ignores and add rules counts

* sort eslint ignores

* fix eslint ignores grammar

* Revert "Fix "blank_line_before_statement""

* fix CS 3.46.0
2024-01-04 14:26:35 +01:00

58 lines
1.3 KiB
PHP

<?php
/**
* Roundcube Reconnect Plugin
*
* @version 0.2
*
* @author Sandro Knauß <hefee@debian.org>
* @license GPLv3+
*/
class reconnect extends rcube_plugin
{
private $imap_max_attempts;
/**
* Plugin initialization
*/
public function init()
{
$this->add_hook('storage_connect', [$this, 'storage_connect']);
}
/**
* Storage_connect hook handler
*/
public function storage_connect($args)
{
$rcmail = rcmail::get_instance();
$this->load_config();
$this->imap_max_attempts = $rcmail->config->get('reconnect_imap_max_attempts', 5);
$args['retry'] = ($args['attempt'] <= $this->imap_max_attempts);
if ($args['attempt'] == 1) {
return $args;
}
$storage = rcmail::get_instance()->get_storage();
switch ($storage->get_error_code()) {
case rcube_imap_generic::ERROR_NO:
case rcube_imap_generic::ERROR_BAD:
case rcube_imap_generic::ERROR_BYE:
$args['retry'] = false;
break;
}
if ($args['retry']) {
// if we do a new attempt, sleep 50 to 150ms before retry.
usleep(rand(50 * 1000, 150 * 1000));
}
return $args;
}
}