Import Ruty
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"name": "reconnect",
|
||||
"type": "roundcube-plugin",
|
||||
"description": "Reconnects to server for several attempts.",
|
||||
"license": "GPL-3.0-or-later",
|
||||
"version": "0.2",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Sandro Knauß",
|
||||
"email": "hefee@debian.org"
|
||||
}
|
||||
],
|
||||
"repositories": [
|
||||
{
|
||||
"type": "composer",
|
||||
"url": "https://plugins.roundcube.net"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=7.3.0",
|
||||
"roundcube/plugin-installer": ">=0.1.3"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
<?php
|
||||
|
||||
// Maximum attempts to connect the IMAP server
|
||||
$config['reconnect_imap_max_attempts'] = 5;
|
||||
@@ -0,0 +1,13 @@
|
||||
# RoundCube Reconnect Plugin
|
||||
|
||||
RoundCube reconnect Plugin is a small plugin that will try to reconnect to an
|
||||
IMAP server, if there is no explicit error code replied. If there is a know
|
||||
failure like wrong password, no additional attempts are triggered. This should
|
||||
help in cases, when the connection to the IMAP server is not 100% stable.
|
||||
|
||||
## Configuration
|
||||
|
||||
You can specify the maximum attempts to connect the IMAP server.
|
||||
|
||||
// Maximum attempts to connect the IMAP server
|
||||
$config['reconnect_imap_max_attempts'] = 5;
|
||||
@@ -0,0 +1,55 @@
|
||||
<?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
|
||||
*/
|
||||
function init()
|
||||
{
|
||||
$this->add_hook('storage_connect', [$this, 'storage_connect']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Storage_connect hook handler
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user