diff --git a/example.config.ini b/example.config.ini
index 86f2dec..ee7da6f 100644
--- a/example.config.ini
+++ b/example.config.ini
@@ -5,6 +5,10 @@
; pro tip: Use a wildcard domain like *.yourdomain.com to auto-generate the subdomains (you'll need to add a wildcard dns record too)
DOMAINS=yourdomain,sub.yourdomain,*.mydom.com
+; This variable needs to be set in order for RSS to work
+; The URL of your webserver hosting the GUI. No trailing slash
+URL="http://localhost:8080"
+
; Enable to show a list of all existing accounts with mail
;SHOW_ACCOUNT_LIST=true
diff --git a/web/inc/OpenTrashmailBackend.class.php b/web/inc/OpenTrashmailBackend.class.php
new file mode 100644
index 0000000..8769f3c
--- /dev/null
+++ b/web/inc/OpenTrashmailBackend.class.php
@@ -0,0 +1,119 @@
+url = $url;
+ $this->settings = loadSettings();
+ }
+ public function run(){
+
+ // api calls
+ if($this->url[0]=='api')
+ {
+ switch($this->url[1]){
+ case 'address':
+ return $this->listAccount($_REQUEST['email']?:$this->url[2]);
+ case 'read':
+ return $this->readMail($_REQUEST['email'],$_REQUEST['id']);
+ case 'attachment':
+ return $this->getAttachment($this->url[2],$this->url[3],$this->url[4]);
+ case 'delete':
+ return $this->deleteMail($_REQUEST['email'],$_REQUEST['id']);
+ default:
+ return false;
+ }
+ }
+
+ // rss feed
+ else if($this->url[0]=='rss')
+ {
+ header("Content-Type: application/rss+xml; charset=UTF8");
+ $email = $this->url[1];
+ if (!$email || !filter_var($email, FILTER_VALIDATE_EMAIL)) {
+ http_response_code(404);
+ exit('Error: Email not found');
+ }
+ return $this->renderPartial('rss.xml',[
+ 'email'=>$email,
+ 'emaildata'=>getEmailsOfEmail($email),
+ 'url'=>$this->settings['URL'],
+ ]);
+ }
+
+ else return false;
+ }
+
+ function getAttachment($email,$id,$attachment)
+ {
+ if(!filter_var($email, FILTER_VALIDATE_EMAIL))
+ return $this->error('Invalid email address');
+ else if(!ctype_digit($id))
+ return $this->error('Invalid id');
+ else if(!emailIDExists($email,$id))
+ return $this->error('Email not found');
+ else if(!attachmentExists($email,$id,$attachment))
+ return $this->error('Attachment not found');
+ $dir = getDirForEmail($email);
+ $file = $dir.DS.'attachments'.DS.$id.'-'.$attachment;
+ $mime = mime_content_type($file);
+ header('Content-Type: '.$mime);
+ header('Content-Length: ' . filesize($file));
+ readfile($file);
+ exit;
+ }
+
+ function readMail($email,$id)
+ {
+ if(!filter_var($email, FILTER_VALIDATE_EMAIL))
+ return $this->error('Invalid email address');
+ else if(!ctype_digit($id))
+ return $this->error('Invalid id');
+ else if(!emailIDExists($email,$id))
+ return $this->error('Email not found');
+ $email = getEmail($email,$id);
+ //$email['raw'] = file_get_contents(getDirForEmail($email['email']).DS.$email['id'].'.json');
+ //$email['parsed'] = json_decode($email['raw'],true);
+
+ var_dump($email);
+ return $this->renderPartial('email.html',[
+ 'email'=>$email,
+ 'mailid'=>$id,
+ ]);
+
+ }
+
+ public function listAccount($email)
+ {
+ if(!filter_var($email, FILTER_VALIDATE_EMAIL))
+ return $this->error('Invalid email address');
+ $emails = getEmailsOfEmail($email);
+ var_dump($emails);
+ return $this->renderPartial('email-table.html',[
+ 'email'=>$email,
+ 'emails'=>$emails,
+ 'dateformat'=>$this->settings['DATEFORMAT']
+ ]);
+ }
+
+ public function error($text)
+ {
+ return '
'.$text.'
';
+ }
+
+ public function renderPartial($partialname,$variables=[])
+ {
+ ob_start();
+ if(is_array($variables))
+ extract($variables);
+ if(file_exists(ROOT.DS.'partials'.DS.$partialname.'.php'))
+ include(ROOT.DS.'partials'.DS.$partialname.'.php');
+ $rendered = ob_get_contents();
+ ob_end_clean();
+
+ return $rendered;
+ }
+
+}
\ No newline at end of file
diff --git a/web/inc/core.php b/web/inc/core.php
index df4893e..ed787f2 100644
--- a/web/inc/core.php
+++ b/web/inc/core.php
@@ -144,4 +144,14 @@ function loadSettings()
function escape($str)
{
return htmlspecialchars($str, ENT_QUOTES, 'UTF-8');
+}
+
+function array2ul($array)
+{
+ $out = "";
+ foreach ($array as $key => $elem) {
+ $out .= "- $elem
";
+ }
+ $out .= "
";
+ return $out;
}
\ No newline at end of file
diff --git a/web/index.html b/web/index.html
index 3e778ce..d0042a4 100644
--- a/web/index.html
+++ b/web/index.html
@@ -6,14 +6,14 @@
- Hello, world!
+ Open Trashmail