use Horde imap library

This commit is contained in:
Roland Gruber 2020-02-15 21:23:40 +01:00
parent aa0228c34c
commit 362014ddf6
1 changed files with 17 additions and 19 deletions

View File

@ -228,18 +228,18 @@ class imapAccess extends baseModule {
$prefix = $this->getMailboxPrefix(); $prefix = $this->getMailboxPrefix();
$email_domain = substr(strstr($this->email, '@'), 1); $email_domain = substr(strstr($this->email, '@'), 1);
$imap_admin_password = $this->getAdminPassword(); // check for password for fall back mechanism $password = $this->getAdminPassword(); // check for password for fall back mechanism
if (!isset($_SESSION['imapAdmPass']) && !isset($imap_admin_password)) { if (!isset($_SESSION['imapAdmPass']) && !isset($password)) {
return $this->display_html_password(); return $this->display_html_password();
} }
$return->addLabel(new htmlOutputText(_('Email address'))); $return->addLabel(new htmlOutputText(_('Email address')));
$return->addField(new htmlOutputText($this->email)); $return->addField(new htmlOutputText($this->email));
$imap_admin_user = $this->getAdminUser(); $user = $this->getAdminUser();
$imap_admin_password = $this->getAdminPassword(); $password = $this->getAdminPassword();
try { try {
$client = $this->connect($imap_admin_user, $imap_admin_password); $client = $this->connect($user, $password);
} }
catch (LAMException $e) { catch (LAMException $e) {
return $this->display_html_password(new htmlStatusMessage('ERROR', $e->getTitle(), $e->getMessage())); return $this->display_html_password(new htmlStatusMessage('ERROR', $e->getTitle(), $e->getMessage()));
@ -885,28 +885,26 @@ class imapAccess extends baseModule {
$limit = $data['limit']; $limit = $data['limit'];
$email_domain = $data['email']; $email_domain = $data['email'];
ob_start(); ob_start();
$imap_server_address = $this->getServerAddress(); $imapUser = $this->getAdminUser();
$imap_admin_user = $this->getAdminUser(); $imapPassword = $this->getAdminPassword();
$imap_admin_password = $this->getAdminPassword(); try {
$imapConnection = 0;//default state is false $client = $this->connect($imapUser, $imapPassword);
if ($imap_admin_password) {
$imapConnection = @imap_open("{" . $imap_server_address . "}", $imap_admin_user, $imap_admin_password, OP_HALFOPEN, 1);
$prefix = $this->getMailboxPrefix(); $prefix = $this->getMailboxPrefix();
$list = imap_list($imapConnection, "{" . $imap_server_address . "}", $prefix . $this->getSep() . $uid); $list = $client->listMailboxes($prefix . $this->getSep() . $uid);
if (empty($list)) { if (empty($list)) {
$createErrors = $this->createMailbox($imapConnection, $uid, $email_domain); $createErrors = $this->createMailbox($client, $uid, $email_domain);
$errors = array_merge($errors, $createErrors); $errors = array_merge($errors, $createErrors);
if (empty($createErrors)) { if (empty($createErrors)) {
$quotaErrors = $this->setQuota($imapConnection, $uid, $email_domain, $limit); $quotaErrors = $this->setQuota($client, $uid, $email_domain, $limit);
$errors = array_merge($errors, $quotaErrors); $errors = array_merge($errors, $quotaErrors);
} }
} }
$client->logout();
} }
if ($imapConnection) { catch (Exception $e) {
imap_close($imapConnection); $message = $this->messages['managemailbox'][5];
} $message[] = $e->getMessage();
else { $errors[] = $message;
$errors[] = $this->messages['managemailbox'][5];
} }
ob_end_clean(); ob_end_clean();
$temp['counter']++; $temp['counter']++;