few reworks
This commit is contained in:
parent
092123175d
commit
752cd0e35f
|
@ -18,8 +18,10 @@ class OpenTrashmailBackend{
|
||||||
return $this->listAccount($_REQUEST['email']?:$this->url[2]);
|
return $this->listAccount($_REQUEST['email']?:$this->url[2]);
|
||||||
case 'read':
|
case 'read':
|
||||||
return $this->readMail($_REQUEST['email'],$_REQUEST['id']);
|
return $this->readMail($_REQUEST['email'],$_REQUEST['id']);
|
||||||
|
case 'raw':
|
||||||
|
return $this->getRawMail($this->url[2],$this->url[3]);
|
||||||
case 'attachment':
|
case 'attachment':
|
||||||
return $this->getAttachment($this->url[2],$this->url[3],$this->url[4]);
|
return $this->getAttachment($this->url[2],$this->url[3]);
|
||||||
case 'delete':
|
case 'delete':
|
||||||
return $this->deleteMail($_REQUEST['email'],$_REQUEST['id']);
|
return $this->deleteMail($_REQUEST['email'],$_REQUEST['id']);
|
||||||
default:
|
default:
|
||||||
|
@ -36,7 +38,7 @@ class OpenTrashmailBackend{
|
||||||
http_response_code(404);
|
http_response_code(404);
|
||||||
exit('Error: Email not found');
|
exit('Error: Email not found');
|
||||||
}
|
}
|
||||||
return $this->renderPartial('rss.xml',[
|
return $this->renderTemplate('rss.xml',[
|
||||||
'email'=>$email,
|
'email'=>$email,
|
||||||
'emaildata'=>getEmailsOfEmail($email),
|
'emaildata'=>getEmailsOfEmail($email),
|
||||||
'url'=>$this->settings['URL'],
|
'url'=>$this->settings['URL'],
|
||||||
|
@ -46,8 +48,24 @@ class OpenTrashmailBackend{
|
||||||
else return false;
|
else return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getAttachment($email,$id,$attachment)
|
function getRawMail($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');
|
||||||
|
$emaildata = getEmail($email,$id);
|
||||||
|
header('Content-Type: text/plain');
|
||||||
|
echo $emaildata['raw'];
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getAttachment($email,$attachment)
|
||||||
|
{
|
||||||
|
$id = substr($attachment,0,13);
|
||||||
|
$attachment = substr($attachment,14);
|
||||||
if(!filter_var($email, FILTER_VALIDATE_EMAIL))
|
if(!filter_var($email, FILTER_VALIDATE_EMAIL))
|
||||||
return $this->error('Invalid email address');
|
return $this->error('Invalid email address');
|
||||||
else if(!ctype_digit($id))
|
else if(!ctype_digit($id))
|
||||||
|
@ -73,12 +91,13 @@ class OpenTrashmailBackend{
|
||||||
return $this->error('Invalid id');
|
return $this->error('Invalid id');
|
||||||
else if(!emailIDExists($email,$id))
|
else if(!emailIDExists($email,$id))
|
||||||
return $this->error('Email not found');
|
return $this->error('Email not found');
|
||||||
$email = getEmail($email,$id);
|
$emaildata = getEmail($email,$id);
|
||||||
//$email['raw'] = file_get_contents(getDirForEmail($email['email']).DS.$email['id'].'.json');
|
//$email['raw'] = file_get_contents(getDirForEmail($email['email']).DS.$email['id'].'.json');
|
||||||
//$email['parsed'] = json_decode($email['raw'],true);
|
//$email['parsed'] = json_decode($email['raw'],true);
|
||||||
|
|
||||||
var_dump($email);
|
var_dump($emaildata);
|
||||||
return $this->renderPartial('email.html',[
|
return $this->renderTemplate('email.html',[
|
||||||
|
'emaildata'=>$emaildata,
|
||||||
'email'=>$email,
|
'email'=>$email,
|
||||||
'mailid'=>$id,
|
'mailid'=>$id,
|
||||||
]);
|
]);
|
||||||
|
@ -91,7 +110,7 @@ class OpenTrashmailBackend{
|
||||||
return $this->error('Invalid email address');
|
return $this->error('Invalid email address');
|
||||||
$emails = getEmailsOfEmail($email);
|
$emails = getEmailsOfEmail($email);
|
||||||
var_dump($emails);
|
var_dump($emails);
|
||||||
return $this->renderPartial('email-table.html',[
|
return $this->renderTemplate('email-table.html',[
|
||||||
'email'=>$email,
|
'email'=>$email,
|
||||||
'emails'=>$emails,
|
'emails'=>$emails,
|
||||||
'dateformat'=>$this->settings['DATEFORMAT']
|
'dateformat'=>$this->settings['DATEFORMAT']
|
||||||
|
@ -103,13 +122,15 @@ class OpenTrashmailBackend{
|
||||||
return '<h1>'.$text.'</h1>';
|
return '<h1>'.$text.'</h1>';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function renderPartial($partialname,$variables=[])
|
public function renderTemplate($templatename,$variables=[])
|
||||||
{
|
{
|
||||||
ob_start();
|
ob_start();
|
||||||
if(is_array($variables))
|
if(is_array($variables))
|
||||||
extract($variables);
|
extract($variables);
|
||||||
if(file_exists(ROOT.DS.'partials'.DS.$partialname.'.php'))
|
if(file_exists(ROOT.DS.'templates'.DS.$templatename.'.php'))
|
||||||
include(ROOT.DS.'partials'.DS.$partialname.'.php');
|
include(ROOT.DS.'templates'.DS.$templatename.'.php');
|
||||||
|
else if(file_exists(ROOT.DS.'templates'.DS.$templatename))
|
||||||
|
include(ROOT.DS.'templates'.DS.$templatename);
|
||||||
$rendered = ob_get_contents();
|
$rendered = ob_get_contents();
|
||||||
ob_end_clean();
|
ob_end_clean();
|
||||||
|
|
||||||
|
|
|
@ -7,14 +7,16 @@ include_once(ROOT.DS.'inc'.DS.'core.php');
|
||||||
|
|
||||||
$url = array_filter(explode('/',ltrim(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH),'/')));
|
$url = array_filter(explode('/',ltrim(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH),'/')));
|
||||||
|
|
||||||
|
$backend = new OpenTrashmailBackend($url);
|
||||||
|
|
||||||
if($_SERVER['HTTP_HX_REQUEST']!='true')
|
if($_SERVER['HTTP_HX_REQUEST']!='true')
|
||||||
{
|
{
|
||||||
if(count($url)==0 || !file_exists(ROOT.DS.implode('/', $url)))
|
if(count($url)==0 || !file_exists(ROOT.DS.implode('/', $url)))
|
||||||
if($url[0]!='api' && $url[0]!='rss')
|
if($url[0]!='api' && $url[0]!='rss')
|
||||||
exit(file_get_contents(ROOT.DS.'index.html'));
|
exit($backend->renderTemplate('index.html'));
|
||||||
}
|
}
|
||||||
|
|
||||||
$backend = new OpenTrashmailBackend($url);
|
|
||||||
$answer = $backend->run();
|
$answer = $backend->run();
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,29 +0,0 @@
|
||||||
<article>
|
|
||||||
<header>Subject: <?= escape($email['parsed']['subject']) ?></header>
|
|
||||||
<header>
|
|
||||||
Reciepients:
|
|
||||||
<div>
|
|
||||||
<?php foreach($email['rcpts'] as $to): ?>
|
|
||||||
<small class="badge"><?= escape($to) ?></small>
|
|
||||||
<?php endforeach; ?>
|
|
||||||
</div>
|
|
||||||
</header>
|
|
||||||
<?= nl2br(escape($email['parsed']['body'])) ?>
|
|
||||||
<footer>
|
|
||||||
Attachments
|
|
||||||
<div>
|
|
||||||
<?php if(count($email['parsed']['attachments'])==0): ?>
|
|
||||||
<small class="secondary">No attachments</small>
|
|
||||||
<?php endif; ?>
|
|
||||||
<ul>
|
|
||||||
<?php foreach($email['parsed']['attachments'] as $attachment): ?>
|
|
||||||
<li>
|
|
||||||
<a href="/api/attachment/<?= $mailid ?>/<?= $attachment ?>"><?= escape($attachment) ?></a>
|
|
||||||
</li>
|
|
||||||
<?php endforeach; ?>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
</footer>
|
|
||||||
</article>
|
|
||||||
|
|
||||||
<div hx-push-url="/eml/<?= $email ?>/<?= $mailid ?>" hx-trigger="load">
|
|
|
@ -38,4 +38,4 @@
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
<div hx-push-url="/eml/<?= $email ?>" hx-trigger="load">
|
<script>history.pushState({email:"<?= $email ?>"}, "", "/eml/<?= $email ?>");</script>
|
36
web/templates/email.html.php
Normal file
36
web/templates/email.html.php
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
<article>
|
||||||
|
<header>Subject: <?= escape($emaildata['parsed']['subject']) ?></header>
|
||||||
|
<header>
|
||||||
|
Reciepients:
|
||||||
|
<div>
|
||||||
|
<?php foreach ($emaildata['rcpts'] as $to) : ?>
|
||||||
|
<small class="badge"><?= escape($to) ?></small>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
<?= nl2br(escape($emaildata['parsed']['body'])) ?>
|
||||||
|
<footer>
|
||||||
|
Attachments
|
||||||
|
<div>
|
||||||
|
<?php if (count($emaildata['parsed']['attachments']) == 0) : ?>
|
||||||
|
<small class="secondary">No attachments</small>
|
||||||
|
<?php endif; ?>
|
||||||
|
<ul>
|
||||||
|
<?php foreach ($emaildata['parsed']['attachments'] as $attachment) : ?>
|
||||||
|
<li>
|
||||||
|
<a target="_blank" href="/api/attachment/<?= $email ?>/<?= $attachment ?>"><?= escape($attachment) ?></a>
|
||||||
|
</li>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</footer>
|
||||||
|
</article>
|
||||||
|
|
||||||
|
<article>
|
||||||
|
<header>Raw email</header>
|
||||||
|
<a href="/api/raw/<?= $email ?>/<?= $mailid ?>" target="_blank">Open in new Window</a>
|
||||||
|
<pre><button hx-get="/api/raw/<?= $email ?>/<?= $mailid ?>" hx-swap="outerHTML">Load Raw Email</button></pre>
|
||||||
|
</article>
|
||||||
|
|
||||||
|
|
||||||
|
<script>history.pushState({email:"<?= $email ?>"}, "", "/eml/<?= $email ?>/<?= $mailid ?>");</script>
|
|
@ -20,9 +20,8 @@
|
||||||
$parts = explode('-', $filename);
|
$parts = explode('-', $filename);
|
||||||
$fid = $parts[0];
|
$fid = $parts[0];
|
||||||
$fn = $parts[1];
|
$fn = $parts[1];
|
||||||
$url = 'https://' . $url . '/api.php?a=attachment&email=' . $email . '&id=' . $fid . '&filename=' . $fn;
|
$att_url = $url . '/api/attachment/' . $email . '/' . $filename;
|
||||||
//$encl[] = '<enclosure url="'.rawurlencode($url).'" length="'.filesize($filepath).'" type="'.mime_content_type($filepath).'" />';
|
$att_text[] = "<a href='$att_url' target='_blank'>$fn</a>";
|
||||||
$att_text[] = "<a href='$url' target='_blank'>$fn</a>";
|
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
<item>
|
<item>
|
||||||
|
@ -34,7 +33,7 @@
|
||||||
Email from: <?= escape($d['from']) ?><br/>
|
Email from: <?= escape($d['from']) ?><br/>
|
||||||
Email to: <?= escape(implode(';',$data['rcpts'])) ?><br/>
|
Email to: <?= escape(implode(';',$data['rcpts'])) ?><br/>
|
||||||
<?= ((count($att_text) > 0) ? 'Attachments:<br/>' . array2ul($att_text) . '<br/>' : '') ?>
|
<?= ((count($att_text) > 0) ? 'Attachments:<br/>' . array2ul($att_text) . '<br/>' : '') ?>
|
||||||
<a href="<?= $url ?>api/eml/test@0xv.eu/1699459401553/raw">View raw email</a> <br/>
|
<a href="<?= $url ?>api/raw/test@0xv.eu/1699459401553">View raw email</a> <br/>
|
||||||
<br/>---------<br/><br/>
|
<br/>---------<br/><br/>
|
||||||
<?= ($data['parsed']['htmlbody'] ? $data['parsed']['htmlbody'] : nl2br(htmlentities($data['parsed']['body']))) ?>
|
<?= ($data['parsed']['htmlbody'] ? $data['parsed']['htmlbody'] : nl2br(htmlentities($data['parsed']['body']))) ?>
|
||||||
]]>
|
]]>
|
Loading…
Reference in a new issue