Skip to content

Commit

Permalink
Move IMAP validation code into UI library
Browse files Browse the repository at this point in the history
  • Loading branch information
slusarz committed Feb 5, 2014
1 parent 9ba5c76 commit 2b67268
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 29 deletions.
26 changes: 26 additions & 0 deletions ingo/lib/Basic/Base.php
Expand Up @@ -68,6 +68,32 @@ public function status()
return Horde::endBuffer();
}

/**
* Validates an IMAP mailbox provided by user input.
*
* @param string $name The form name of the input.
*
* @return string The IMAP mailbox name.
* @throws Horde_Exception
*/
public function validateMbox($name)
{
global $registry;

$new_id = $name . '_new';

if (isset($this->vars->$new_id)) {
if ($registry->hasMethod('mail/createMailbox') &&
$registry->call('mail/createMailbox', array($this->vars->$new_id))) {
return $this->vars->$new_id;
}
} elseif (strlen($this->vars->$name)) {
return $this->vars->$name;
}

throw new Ingo_Exception(_("Could not validate IMAP mailbox."));
}

/**
* Add the ingo action token to a URL.
*
Expand Down
2 changes: 1 addition & 1 deletion ingo/lib/Basic/Blacklist.php
Expand Up @@ -57,7 +57,7 @@ protected function _init()
break;

case 'folder':
$folder = Ingo::validateFolder($this->vars, 'actionvalue');
$folder = $this->validateMbox('actionvalue');
break;
}

Expand Down
2 changes: 1 addition & 1 deletion ingo/lib/Basic/Rule.php
Expand Up @@ -145,7 +145,7 @@ protected function _init()
case 'folder':
if ($actionID == 'rule_save') {
try {
$rule['action-value'] = Ingo::validateFolder($this->vars, 'actionvalue');
$rule['action-value'] = $this->validateMbox('actionvalue');
} catch (Ingo_Exception $e) {
$notification->push($e, 'horde.error');
$actionID = null;
Expand Down
2 changes: 1 addition & 1 deletion ingo/lib/Basic/Spam.php
Expand Up @@ -59,7 +59,7 @@ protected function _init()
$success = false;

try {
$spam->setSpamFolder(Ingo::validateFolder($this->vars, 'folder'));
$spam->setSpamFolder($this->validateMbox('folder'));
$success = true;
} catch (Horde_Exception $e) {
$notification->push($e);
Expand Down
25 changes: 0 additions & 25 deletions ingo/lib/Ingo.php
Expand Up @@ -55,31 +55,6 @@ class Ingo
const RULE_FORWARD = 5;
const RULE_SPAM = 6;

/**
* Validates an IMAP mailbox provided by user input.
*
* @param Horde_Variables $vars An variables object.
* @param string $name The form name of the folder input.
*
* @return string The IMAP mailbox name.
* @throws Horde_Exception
*/
static public function validateFolder(Horde_Variables $vars, $name)
{
$new_id = $name . '_new';

if (isset($vars->$new_id)) {
if ($GLOBALS['registry']->hasMethod('mail/createMailbox') &&
$GLOBALS['registry']->call('mail/createMailbox', array($vars->$new_id))) {
return $vars->$new_id;
}
} elseif (isset($vars->$name) && strlen($vars->$name)) {
return $vars->$name;
}

throw new Ingo_Exception(_("Could not validate IMAP mailbox."));
}

/**
* Returns the user whose rules are currently being edited.
*
Expand Down
2 changes: 1 addition & 1 deletion ingo/templates/flist/select.html.php
Expand Up @@ -8,7 +8,7 @@
}

foreach ($this->mboxes as $v) {
$o .= $this->optionTag($v['ob'], $this->escape(str_repeat(' ', $val['level'] * 2) . $val['label']), $val['ob'] == $this->val);
$o .= $this->optionTag($v['ob'], $this->escape(str_repeat(' ', $v['level'] * 2) . $v['label']), $v['ob'] == $this->val);
}

echo $this->selectTag($this->tagname, $o, array('class' => 'flistSelect'));

0 comments on commit 2b67268

Please sign in to comment.