summaryrefslogtreecommitdiff
path: root/src/controllers/Messages.class.php
diff options
context:
space:
mode:
authorLuke Shumaker <LukeShu@sbcglobal.net>2012-01-07 08:21:00 -0800
committerLuke Shumaker <LukeShu@sbcglobal.net>2012-01-07 10:22:21 -0800
commit83e460cdc3fc09867a3adb48c3d0894579dd3050 (patch)
tree0771bd935b30971bf2c244b6f158ed7496b644e5 /src/controllers/Messages.class.php
parent3d64793a1ee45857856be1cd71c3a0a040a3e869 (diff)
Refactor to separate the framework from the app; drop message stuff, this app is just user management. Add a json view for individual users
Diffstat (limited to 'src/controllers/Messages.class.php')
-rw-r--r--src/controllers/Messages.class.php100
1 files changed, 0 insertions, 100 deletions
diff --git a/src/controllers/Messages.class.php b/src/controllers/Messages.class.php
deleted file mode 100644
index 717e18e..0000000
--- a/src/controllers/Messages.class.php
+++ /dev/null
@@ -1,100 +0,0 @@
-<?php
-require_once('Login.class.php');
-require_once('Auth.class.php');
-
-Router::register('messages', 'Messages', 'index');
-Router::register('messages/index', 'Messages', 'index');
-Router::register('messages/*', 'Messages', 'message');
-
-class Messages extends Controller {
- public static $msgdir;
-
- public function __construct() {
- require_once('MimeMailParser.class.php');
- $this->msgdir = BASEPATH.'/msg';
- }
-
- public function index($routed, $remainder) {
- $parser = new MimeMailParser();
- $messages = array();
- $dh = opendir($this->msgdir);
- while (($file = readdir($dh)) !== false) {
- $path = $this->msgdir."/$file";
- if (is_file($path)) {
- $parser->setPath($path);
-
- $date_string = $parser->getHeader('date');
- $date = strtotime($date_string);
- if (!isset($messages[$date])) {
- $messages[$date] = array();
- }
- $messages[$date][] =
- array('id'=>$file,
- 'subject'=>$parser->getHeader('subject'),
- 'from'=>$parser->getHeader('from'));
- }
- }
- closedir($dh);
-
- $this->showView('messages/index', array('messages' => $messages));
- exit();
- }
-
- public function message($routed, $remainder) {
- $uid = Login::isLoggedIn();
- if ($uid===false || !Auth::getInstance($uid)->isUser()) {
- $this->http401($routed, $remainder);
- return;
- }
-
- $msg_id = $remainder[0];// We can trust the router that this is set
- $msg_file = $this->msgdir."/$msg_id";
- if (!is_file($msg_file)) {
- $this->http404($routed, $remainder);
- return;
- }
-
- @$part = $remainder[1];
- @$subpart = $remainder[2];
- $parser = new MimeMailParser();
- $parser->setPath($msg_file);
-
- switch ($part) {
- case '':
- $this->showView('messages/frame',
- array('msg_id'=>$msg_id,
- 'parser'=>$parser,
- 'msgdir'=>$this->msgdir,
- ));
- break;
- case 'body':
- require_once('Mime.class.php');
- header('Content-type: '.Mime::ext2mime(PAGE_EXT));
- $map = array('html'=>'html',
- 'txt' =>'text');
- echo $parser->getMessageBody($map[PAGE_EXT]);
- break;
- case 'attachment':
- $attachment_id = $subpart;
- $attachments = $parser->getAttachments();
- $attachment = $attachments[$attachment_id];
-
- $type = $attachment->getContentType();
- $filename = $attachment->getFilename();
-
- header('Content-Type: '.$type);
- header('Content-Disposition: attachment; filename='.$filename );
- while($bytes = $attachment->read()) {
- echo $bytes;
- }
- break;
- default:
- array_push($routed, array_shift($remainder));
- $this->http404($routed, $remainder);
- }
- }
-
- public function http401($routed, $remainder) {
- $this->showView('messages/401', array('uid'=>Login::isLoggedIn()));
- }
-} \ No newline at end of file