list mails, read mails
authorMarkus Warg <mw@it-sls.de>
Wed, 14 Apr 2010 14:29:09 +0000 (16:29 +0200)
committerMarkus Warg <mw@it-sls.de>
Wed, 14 Apr 2010 14:29:09 +0000 (16:29 +0200)
fix smaller issues in imap class
mail controller
list contents of mailbox
read mails

manager/application/controllers/MailController.php
manager/application/views/scripts/mail/index.phtml
manager/application/views/scripts/mail/read.phtml [new file with mode: 0644]
manager/library/imap/imapConnection.php
manager/public/css/mail.css [new file with mode: 0644]

index afe902b..5ee84d4 100644 (file)
@@ -16,9 +16,35 @@ class MailController extends Zend_Controller_Action
 
     public function indexAction()
     {
-        // action body
+       $config = Zend_Registry::get('config');
+               $imap_config = $config->imap;
+        $imap = imapConnection::getInstance('cacert', $imap_config);
+               $imap->imapSwitchMbox('INBOX');
+
+        $ck = $imap->imapCheck();
+
+        $headers = array();
+        for ($i=0; $i < $ck->Nmsgs; $i++) {
+               $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);
+               $headers[] = $header;
+        }
+
+        $this->view->headers = $headers;
     }
 
+    public function readAction()
+    {
+       $config = Zend_Registry::get('config');
+               $imap_config = $config->imap;
+        $imap = imapConnection::getInstance('cacert', $imap_config);
+               $imap->imapSwitchMbox('INBOX');
+
+               $uid = $this->getRequest()->getParam('uid');
 
-}
+               $body = $imap->imapBodyByUID($uid);
 
+               $this->view->mail_body = $body;
+    }
+}
index 4cbadc3..faf6bd4 100644 (file)
@@ -3,5 +3,26 @@
  * @author markus\r
  * $Id: index.phtml 25 2009-12-02 15:43:21Z markus $\r
  */\r
+$this->headLink()->appendStylesheet('/css/mail.css');\r
 ?>\r
 <H1><?php print I18n::_('Mail'); ?></H1>\r
+<table>\r
+       <tr>\r
+               <th><?php print I18n::_('From');?></th>\r
+               <th><?php print I18n::_('To');?></th>\r
+               <th><?php print I18n::_('Subject');?></th>\r
+               <th><?php print I18n::_('Date');?></th>\r
+               <th><?php print I18n::_('Size');?></th>\r
+       </tr>\r
+<?php\r
+foreach ($this->headers as $header) {\r
+       print "        <tr>\n";\r
+       print "            <td><a href=\"" . $header->detailslink . "\">" . $header->fromaddress . "</a></td>";\r
+       print "            <td>" . $header->toaddress . "</td>";\r
+       print "            <td>" . $header->subject . "</td>";\r
+       print "            <td>" . $header->date . "</td>";\r
+       print "            <td>" . $header->Size . "</td>";\r
+       print "        </tr>\n";\r
+}\r
+?>\r
+</table>\r
diff --git a/manager/application/views/scripts/mail/read.phtml b/manager/application/views/scripts/mail/read.phtml
new file mode 100644 (file)
index 0000000..1d64d5e
--- /dev/null
@@ -0,0 +1,10 @@
+<?php\r
+/**\r
+ * @author markus\r
+ * $Id: index.phtml 25 2009-12-02 15:43:21Z markus $\r
+ */\r
+$this->headLink()->appendStylesheet('/css/mail.css');\r
+?>\r
+<H1><?php print I18n::_('Read Mail'); ?></H1>\r
+<?php\r
+print_r($this->mail_body);
\ No newline at end of file
index f78dc3d..1528a76 100644 (file)
@@ -407,8 +407,8 @@ class imapConnection {
         if ($ret === false) {
             if ($reconnect === true) {
                                $this->imap = $this->imapOpen($this->server.$this->mbox,
-                                       $this->config->getValue('username'),
-                                       $this->config->getValue('password'),
+                                       $this->config->username,
+                                       $this->config->password,
                                        OP_HALFOPEN);
 
                 $ret = imap_ping($this->imap);
@@ -471,26 +471,26 @@ class imapConnection {
         * @param $instanceName
         * @param $config
         */
-       protected function __construct($instanceName,$config) {
+       protected function __construct($instanceName, $config) {
                $this->instanceName = $instanceName;
                $this->config = $config;
 
-               if (!$this->config->hasValue('mailhost')) {
+               if (!isset($this->config->mailhost)) {
                        throw new IMAPException(__METHOD__ . ' config attribute missing: "mailhost"');
                }
-               if (!$this->config->hasValue('username')) {
+               if (!isset($this->config->username)) {
                        throw new IMAPException(__METHOD__ . ' config attribute missing: "username"');
                }
-               if (!$this->config->hasValue('password')) {
+               if (!isset($this->config->password)) {
                        throw new IMAPException(__METHOD__ . ' config attribute missing: "password"');
                }
-               if (!$this->config->hasValue('port')) {
+               if (!isset($this->config->port)) {
                        throw new IMAPException(__METHOD__ . ' config attribute missing: "port"');
                }
 
-               $this->server = '{'.$this->config->getValue('mailhost').':'.$this->config->getValue('port').'/imap';
-               if( $this->config->hasValue('use_tls') &&
-                       $this->config->getValue('use_tls') == true ) {
+               $this->server = '{'.$this->config->mailhost.':'.$this->config->port.'/imap';
+               if( isset($this->config->use_tls) &&
+                       $this->config->use_tls != 0 ) {
                        $this->server .= '/tls';
                }
                $this->server .= '/novalidate-cert}';
@@ -502,8 +502,8 @@ class imapConnection {
                $this->imap = null;
 
                $this->imap = $this->imapOpen($this->server.$mbox,
-                       $this->config->getValue('username'),
-                       $this->config->getValue('password'),
+                       $this->config->username,
+                       $this->config->password,
                        OP_HALFOPEN);
 
                if ($this->imap === false) {
@@ -535,9 +535,11 @@ class imapConnection {
                                return $instance;
                }
 
+               /*
                if (!$config instanceof Config) {
                        throw new IMAPException(__METHOD__ . ' no config');
                }
+               */
 
                $object = new imapConnection($instanceName, $config);
 
diff --git a/manager/public/css/mail.css b/manager/public/css/mail.css
new file mode 100644 (file)
index 0000000..6cd0274
--- /dev/null
@@ -0,0 +1,25 @@
+@CHARSET "UTF-8";\r
+\r
+#content table {\r
+       border: 1px solid black;\r
+       border-collapse: collapse;\r
+}\r
+\r
+#content th {\r
+       border: 1px solid black;\r
+       padding: 3px;\r
+}\r
+\r
+#content td {\r
+       border: 1px solid black;\r
+       padding: 3px;\r
+}\r
+\r
+#content a {\r
+       text-decoration: none;\r
+       color: #000000;\r
+}\r
+\r
+#content a:hover {\r
+       color: #777777;\r
+}\r