2010-04-14 13:20:40 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @author markus
|
|
|
|
* $Id: IndexController.php 6 2009-11-18 14:52:50Z markus $
|
|
|
|
*/
|
|
|
|
|
|
|
|
require_once(LIBRARY_PATH . '/imap/imapConnection.php');
|
|
|
|
|
|
|
|
class MailController extends Zend_Controller_Action
|
|
|
|
{
|
2015-08-09 17:12:51 +00:00
|
|
|
/**
|
|
|
|
* list of email addresses associated with that account
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
private $addresses = array();
|
2010-04-14 13:20:40 +00:00
|
|
|
|
|
|
|
public function init()
|
|
|
|
{
|
|
|
|
/* Initialize action controller here */
|
2015-08-09 17:12:51 +00:00
|
|
|
$session = Zend_Registry::get('session');
|
|
|
|
$auth = $session->authdata['authed_permissions'];
|
|
|
|
|
|
|
|
$action = $this->getRequest()->getActionName();
|
|
|
|
|
|
|
|
$this->view->leftNav('<a href="' .
|
|
|
|
$this->view->url(array('controller' => 'mail', 'action' => 'index'), 'default', true) .
|
|
|
|
'"' . (($action == 'index')?' class="active"':'') . '>' . I18n::_('View own Mails') . '</a>', Zend_View_Helper_Placeholder_Container_Abstract::SET, 1);
|
|
|
|
if ($session->authdata['authed_role'] == 'Admin') {
|
|
|
|
$this->view->leftNav('<a href="' .
|
|
|
|
$this->view->url(array('controller' => 'mail', 'action' => 'full'), 'default', true) .
|
|
|
|
'"' . (($action == 'full')?' class="active"':'') . '>' . I18n::_('View all Mails') . '</a>', Zend_View_Helper_Placeholder_Container_Abstract::SET, 2);
|
|
|
|
}
|
2010-08-18 12:57:13 +00:00
|
|
|
|
2015-08-09 17:12:51 +00:00
|
|
|
$config = new Zend_Config_Ini(APPLICATION_PATH . '/configs/application.ini', APPLICATION_ENV);
|
|
|
|
$db = Zend_Db::factory($config->ca_mgr->db->auth->pdo, $config->ca_mgr->db->auth);
|
|
|
|
$emails = new CAcert_User_Emails($db);
|
2010-08-18 12:57:13 +00:00
|
|
|
|
2015-08-09 17:12:51 +00:00
|
|
|
$this->addresses = $emails->getEmailAddressesByLogin($session->authdata['authed_username']);
|
2010-08-18 12:57:13 +00:00
|
|
|
|
2010-04-14 13:20:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function indexAction()
|
|
|
|
{
|
2015-08-09 17:12:51 +00:00
|
|
|
$config = Zend_Registry::get('config');
|
|
|
|
$session = Zend_Registry::get('session');
|
2010-07-07 07:41:44 +00:00
|
|
|
|
2015-08-09 17:12:51 +00:00
|
|
|
$imap_config = $config->imap;
|
2010-07-07 07:41:44 +00:00
|
|
|
$imap = imapConnection::getInstance('cacert', $imap_config);
|
2015-08-09 17:12:51 +00:00
|
|
|
$imap->imapSwitchMbox('INBOX');
|
2010-07-07 07:41:44 +00:00
|
|
|
|
|
|
|
$ck = $imap->imapCheck();
|
|
|
|
|
|
|
|
$headers = array();
|
|
|
|
for ($i=0; $i < $ck->Nmsgs; $i++) {
|
2015-08-09 17:12:51 +00:00
|
|
|
$header = $imap->imapHeader($i+1);
|
2010-07-07 07:41:44 +00:00
|
|
|
|
2015-08-09 17:12:51 +00:00
|
|
|
// skip all emails that do not belong to the user
|
|
|
|
if (!in_array($header->toaddress, $this->addresses))
|
|
|
|
continue;
|
2010-07-07 07:41:44 +00:00
|
|
|
|
2015-08-09 17:12:51 +00:00
|
|
|
$header->uid = $imap->imapUID($i+1);
|
|
|
|
$header->detailslink = $this->view->url(array('controller' => 'mail', 'action' => 'read', 'uid' => $header->uid), 'default', true);
|
|
|
|
$header->deletelink = $this->view->url(array('controller' => 'mail', 'action' => 'delete', 'uid' => $header->uid), 'default', true);
|
|
|
|
$headers[] = $header;
|
2010-07-07 07:41:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$this->view->headers = $headers;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function fullAction()
|
|
|
|
{
|
2015-08-09 17:12:51 +00:00
|
|
|
$config = Zend_Registry::get('config');
|
2010-07-07 07:41:44 +00:00
|
|
|
|
2015-08-09 17:12:51 +00:00
|
|
|
$imap_config = $config->imap;
|
2010-04-14 14:29:09 +00:00
|
|
|
$imap = imapConnection::getInstance('cacert', $imap_config);
|
2015-08-09 17:12:51 +00:00
|
|
|
$imap->imapSwitchMbox('INBOX');
|
2010-04-14 14:29:09 +00:00
|
|
|
|
|
|
|
$ck = $imap->imapCheck();
|
|
|
|
|
|
|
|
$headers = array();
|
|
|
|
for ($i=0; $i < $ck->Nmsgs; $i++) {
|
2015-08-09 17:12:51 +00:00
|
|
|
$header = $imap->imapHeader($i+1);
|
|
|
|
$header->uid = $imap->imapUID($i+1);
|
|
|
|
$header->detailslink = $this->view->url(array('controller' => 'mail', 'action' => 'read', 'uid' => $header->uid), 'default', true);
|
|
|
|
$header->deletelink = $this->view->url(array('controller' => 'mail', 'action' => 'delete', 'uid' => $header->uid), 'default', true);
|
|
|
|
$headers[] = $header;
|
2010-04-14 14:29:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$this->view->headers = $headers;
|
2010-04-14 13:20:40 +00:00
|
|
|
}
|
|
|
|
|
2010-04-14 14:29:09 +00:00
|
|
|
public function readAction()
|
|
|
|
{
|
2015-08-09 17:12:51 +00:00
|
|
|
$config = Zend_Registry::get('config');
|
|
|
|
$imap_config = $config->imap;
|
2010-04-14 14:29:09 +00:00
|
|
|
$imap = imapConnection::getInstance('cacert', $imap_config);
|
2015-08-09 17:12:51 +00:00
|
|
|
$imap->imapSwitchMbox('INBOX');
|
2010-04-14 14:29:09 +00:00
|
|
|
|
2015-08-09 17:12:51 +00:00
|
|
|
$uid = $this->getRequest()->getParam('uid');
|
2010-04-14 13:20:40 +00:00
|
|
|
|
2015-08-09 17:12:51 +00:00
|
|
|
$body = $imap->imapBodyByUID($uid);
|
2010-04-14 13:20:40 +00:00
|
|
|
|
2015-08-09 17:12:51 +00:00
|
|
|
$this->view->mail_body = $body;
|
2010-04-14 14:29:09 +00:00
|
|
|
}
|
2010-07-07 07:41:44 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* delete message with unique id
|
|
|
|
*/
|
2015-08-09 17:12:51 +00:00
|
|
|
public function deleteAction()
|
2010-07-07 07:41:44 +00:00
|
|
|
{
|
2015-08-09 17:12:51 +00:00
|
|
|
$config = Zend_Registry::get('config');
|
|
|
|
$uid = $this->getRequest()->getParam('uid', -1);
|
|
|
|
$this->view->returnto = $_SERVER['HTTP_REFERER'];
|
|
|
|
|
|
|
|
if ($uid == -1) {
|
|
|
|
$this->view->message = I18n::_('You did not select an email for deletion');
|
|
|
|
}
|
|
|
|
elseif ($this->view->returnto == '') {
|
|
|
|
$this->view->message = I18n::_('Please use the delete icons in the mail inventory to delete mails');
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$imap_config = $config->imap;
|
|
|
|
$imap = imapConnection::getInstance('cacert', $imap_config);
|
|
|
|
$imap->imapSwitchMbox('INBOX');
|
|
|
|
|
|
|
|
$header = $imap->imapFetchOverview($uid);
|
|
|
|
|
|
|
|
$session = Zend_Registry::get('session');
|
|
|
|
|
|
|
|
if ($session->authdata['authed_role'] != 'Admin' && !in_array($header->to, $this->addresses)) {
|
|
|
|
$this->view->message = I18n::_('This message does not belong to you');
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$imap->imapDelete($uid);
|
|
|
|
$imap->imapExpunge();
|
|
|
|
$this->view->message = I18n::_('Message deleted');
|
|
|
|
}
|
|
|
|
}
|
2010-07-07 07:41:44 +00:00
|
|
|
}
|
2010-04-14 14:29:09 +00:00
|
|
|
}
|