From df1d6abc414504d7fcf841daee31f454b277926a Mon Sep 17 00:00:00 2001 From: wangchunsheng Date: Sat, 29 Oct 2011 08:04:04 +0000 Subject: [PATCH] * rewrite the sendmail logic. task#566. --- module/mail/model.php | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/module/mail/model.php b/module/mail/model.php index b17662c4e5..b636ddedab 100644 --- a/module/mail/model.php +++ b/module/mail/model.php @@ -113,17 +113,22 @@ class mailModel extends model { if(!$this->config->mail->turnon) return; + /* Process toList and ccList, remove current user from them. If toList is empty, use the first cc as to. */ + $account = $this->app->user->account; + $toList = $toList ? explode(',', str_replace(' ', '', $toList)) : array(); + $ccList = $ccList ? explode(',', str_replace(' ', '', $ccList)) : array(); + + foreach($toList as $key => $to) if(trim($to) == $account or !trim($to)) unset($toList[$key]); + foreach($ccList as $key => $cc) if(trim($cc) == $account or !trim($cc)) unset($ccList[$key]); + + if(!$toList and !$ccList) return; + if(!$toList and $ccList) $toList = array(array_shift($ccList)); + $toList = join(',', $toList); + $ccList = join(',', $ccList); + /* Get realname and email of users. */ $this->loadModel('user'); - $list = $toList . ',' . $ccList; - if(substr_count($list, $this->app->user->account) != 0 and $test != 'test') - { - $listArray = explode(",", $list); - unset($list); - $list = ''; - foreach($listArray as $data) if($data != $this->app->user->account) $list = $list . $data . ','; - } - $emails = $this->user->getRealNameAndEmails(str_replace(' ', '', $list)); + $emails = $this->user->getRealNameAndEmails(str_replace(' ', '', $toList . ',' . $ccList)); $this->clear();