4 * $Id: IndexController.php 6 2009-11-18 14:52:50Z markus $
7 require_once(LIBRARY_PATH
. '/imap/imapConnection.php');
9 class MailController
extends Zend_Controller_Action
12 * list of email addresses associated with that account
15 private $addresses = array();
17 public function init()
19 /* Initialize action controller here */
20 $session = Zend_Registry
::get('session');
21 $auth = $session->authdata
['authed_permissions'];
23 $action = $this->getRequest()->getActionName();
25 $this->view
->leftNav('<a href="' .
26 $this->view
->url(array('controller' => 'mail', 'action' => 'index'), 'default', true
) .
27 '"' . (($action == 'index')?
' class="active"':'') . '>' . I18n
::_('View own Mails') . '</a>', Zend_View_Helper_Placeholder_Container_Abstract
::SET
, 1);
28 if ($session->authdata
['authed_role'] == 'Admin') {
29 $this->view
->leftNav('<a href="' .
30 $this->view
->url(array('controller' => 'mail', 'action' => 'full'), 'default', true
) .
31 '"' . (($action == 'full')?
' class="active"':'') . '>' . I18n
::_('View all Mails') . '</a>', Zend_View_Helper_Placeholder_Container_Abstract
::SET
, 2);
34 $config = new Zend_Config_Ini(APPLICATION_PATH
. '/configs/application.ini', APPLICATION_ENV
);
35 $db = Zend_Db
::factory($config->ca_mgr
->db
->auth
->pdo
, $config->ca_mgr
->db
->auth
);
36 $emails = new CAcert_User_Emails($db);
38 $this->addresses
= $emails->getEmailAddressesByLogin($session->authdata
['authed_username']);
42 public function indexAction()
44 $config = Zend_Registry
::get('config');
45 $session = Zend_Registry
::get('session');
47 $imap_config = $config->imap
;
48 $imap = imapConnection
::getInstance('cacert', $imap_config);
49 $imap->imapSwitchMbox('INBOX');
51 $ck = $imap->imapCheck();
54 for ($i=0; $i < $ck->Nmsgs
; $i++
) {
55 $header = $imap->imapHeader($i+
1);
57 // skip all emails that do not belong to the user
58 if (!in_array($header->toaddress
, $this->addresses
))
61 $header->uid
= $imap->imapUID($i+
1);
62 $header->detailslink
= $this->view
->url(array('controller' => 'mail', 'action' => 'read', 'uid' => $header->uid
), 'default', true
);
63 $header->deletelink
= $this->view
->url(array('controller' => 'mail', 'action' => 'delete', 'uid' => $header->uid
), 'default', true
);
67 $this->view
->headers
= $headers;
70 public function fullAction()
72 $config = Zend_Registry
::get('config');
74 $imap_config = $config->imap
;
75 $imap = imapConnection
::getInstance('cacert', $imap_config);
76 $imap->imapSwitchMbox('INBOX');
78 $ck = $imap->imapCheck();
81 for ($i=0; $i < $ck->Nmsgs
; $i++
) {
82 $header = $imap->imapHeader($i+
1);
83 $header->uid
= $imap->imapUID($i+
1);
84 $header->detailslink
= $this->view
->url(array('controller' => 'mail', 'action' => 'read', 'uid' => $header->uid
), 'default', true
);
85 $header->deletelink
= $this->view
->url(array('controller' => 'mail', 'action' => 'delete', 'uid' => $header->uid
), 'default', true
);
89 $this->view
->headers
= $headers;
92 public function readAction()
94 $config = Zend_Registry
::get('config');
95 $imap_config = $config->imap
;
96 $imap = imapConnection
::getInstance('cacert', $imap_config);
97 $imap->imapSwitchMbox('INBOX');
99 $uid = $this->getRequest()->getParam('uid');
101 $body = $imap->imapBodyByUID($uid);
103 $this->view
->mail_body
= $body;
107 * delete message with unique id
109 public function deleteAction()
111 $config = Zend_Registry
::get('config');
112 $uid = $this->getRequest()->getParam('uid', -1);
113 $this->view
->returnto
= $_SERVER['HTTP_REFERER'];
116 $this->view
->message
= I18n
::_('You did not select an email for deletion');
118 elseif ($this->view
->returnto
== '') {
119 $this->view
->message
= I18n
::_('Please use the delete icons in the mail inventory to delete mails');
122 $imap_config = $config->imap
;
123 $imap = imapConnection
::getInstance('cacert', $imap_config);
124 $imap->imapSwitchMbox('INBOX');
126 $header = $imap->imapFetchOverview($uid);
128 $session = Zend_Registry
::get('session');
130 if ($session->authdata
['authed_role'] != 'Admin' && !in_array($header->to
, $this->addresses
)) {
131 $this->view
->message
= I18n
::_('This message does not belong to you');
134 $imap->imapDelete($uid);
135 $imap->imapExpunge();
136 $this->view
->message
= I18n
::_('Message deleted');