summaryrefslogtreecommitdiffstats
path: root/lib/model/Address.php
diff options
context:
space:
mode:
authorGravatar mszulecki2007-06-14 17:09:01 +0000
committerGravatar mszulecki2007-06-14 17:09:01 +0000
commit9f108dd1a969473375341d92a7b1252fa2cedc9a (patch)
treed5f2e35ec0bd2d52dab0ee3282fc6751e0fa8dba /lib/model/Address.php
parente35884d11b81e4e4bbd73e1882e2b8011e85d118 (diff)
downloadmailadmin-9f108dd1a969473375341d92a7b1252fa2cedc9a.tar.gz
mailadmin-9f108dd1a969473375341d92a7b1252fa2cedc9a.tar.bz2
Initial import.
git-svn-id: http://svn.sukimashita.com/repos/mailadmin/trunk@2 4281df72-ff29-0410-8fee-2d9ac0c5f5a7
Diffstat (limited to 'lib/model/Address.php')
-rw-r--r--lib/model/Address.php124
1 files changed, 124 insertions, 0 deletions
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 @@
+<?php
+
+/**
+ * Subclass for representing a row from the 'address' table.
+ *
+ *
+ *
+ * @package lib.model
+ */
+class Address extends BaseAddress
+{
+ protected function splitEmail($v)
+ {
+ return explode("@", $v);
+ }
+
+ public function setLocalpart($v)
+ {
+ // sync alias
+ $alias = $this->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();
+ }
+}