From 9f108dd1a969473375341d92a7b1252fa2cedc9a Mon Sep 17 00:00:00 2001 From: mszulecki Date: Thu, 14 Jun 2007 17:09:01 +0000 Subject: Initial import. git-svn-id: http://svn.sukimashita.com/repos/mailadmin/trunk@2 4281df72-ff29-0410-8fee-2d9ac0c5f5a7 --- lib/model/Address.php | 124 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 124 insertions(+) create mode 100644 lib/model/Address.php (limited to 'lib/model/Address.php') diff --git a/lib/model/Address.php b/lib/model/Address.php new file mode 100644 index 0000000..b6b9cf8 --- /dev/null +++ b/lib/model/Address.php @@ -0,0 +1,124 @@ +splitEmail($this->getAlias()); + if(is_array($alias)) + { + if($alias[0]!=$v) + { + parent::setAlias($v."@".$alias[1]); + } + } + + return parent::setLocalpart($v); + } + + public function setDomainId($v) + { + // sync alias + $alias = $this->splitEmail($this->getAlias()); + if(is_array($alias)) + { + $domain = DomainPeer::retrieveByPk($v); + if($domain) + { + if($alias[(count($alias)>1?1:0)] != $domain) + { + parent::setAlias((count($alias)>1?$alias[0]:"")."@".$domain->getName()); + } + } + } + + return parent::setDomainId($v); + } + + public function setAlias($v) + { + $alias = $this->splitEmail($v); + + // sync localpart + parent::setLocalpart($alias[0]); + + // sync domain_id + $c = new Criteria(); + $c->add(DomainPeer::NAME, $alias[1]); + $domain = DomainPeer::doSelectOne($c); + + if($domain) + parent::setDomainId($domain->getId()); + else + parent::setDomainId(null); + + return parent::setAlias($v); + } + + public function setDestination($dest) + { + // make sure we are a comma seperated string + $destarray = self::getDestinationAsArray($dest); + + // if a mailbox is set, make sure it is first in the list + if($this->getSaveInMailbox()) + { + $mailbox = $this->getMailbox(); + if($mailbox) + { + if(array_search($mailbox->getName(), $destarray) == false) + { + $destarray = array_merge(array($this->getMailbox()->getName()), $destarray); + } + } + + } + + parent::setDestination(implode(",", $destarray)); + } + + public function getDestination($delimiter = '\n') + { + // if a mailbox is set, strip it out of the list + $destarray = self::getDestinationAsArray(parent::getDestination()); + $destarray2 = array(); + if($this->getSaveInMailbox()) + { + foreach($destarray as $dest) + { + if($dest != $this->getMailbox()->getName()) + $destarray2[] = $dest; + } + } + else $destarray2 = $destarray; + return implode("\n", $destarray2); + } + + public static function getDestinationAsArray($d) + { + return preg_split("/[\s\n,;]+/", $d, -1, PREG_SPLIT_NO_EMPTY); + } + + public function isCatchAll() + { + return ($this->getLocalpart()==""); + } + + public function __toString() + { + return $this->getAlias(); + } +} -- cgit v1.1-32-gdbae