Commit 16941b4a authored by thiaramus's avatar thiaramus
Browse files

Transferred new message code from ajax.php

parent e225881e
......@@ -71,7 +71,7 @@
}
private function getMessage() {
$msgId = $this->apiCallPath[2];
$msgId = $this->apiCallPath[2];
$jam = new jam();
......@@ -94,7 +94,101 @@
}
private function newMessage() {
$this->syntaxErrorMessage('Not yet implemented (POST)');
if ($this->user['readonly'] === true) {
$this->syntaxErrorMessage('Logged user has a read only status');
}
$toName = filter_input(INPUT_POST, 'toName', FILTER_SANITIZE_STRING);
$toAka = filter_input(INPUT_POST, 'toAka', FILTER_SANITIZE_STRING);
$subject = filter_input(INPUT_POST, 'subject', FILTER_SANITIZE_STRING);
$message = filter_input(INPUT_POST, 'message', FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES);
$origin = filter_input(INPUT_POST, 'origin', FILTER_SANITIZE_STRING);
$tearline = filter_input(INPUT_POST, 'tearline', FILTER_SANITIZE_STRING);
$replyId = filter_input(INPUT_POST, 'replyId', FILTER_SANITIZE_NUMBER_INT);
if (!$toName) {
$this->syntaxErrorMessage('Recipient name is undefined');
}
// No sure if subject is mandatory or no, so I'll make it mandatory for now
if (!$subject) {
$this->syntaxErrorMessage('Subject is undefined');
}
if (!$message) {
$this->syntaxErrorMessage('Message body is undefined');
}
$fromAka = false;
$defaultAka = false;
$domain = false;
$netmail = false;
// I am not sure about this one for now
// if ( ( $this->areaName == 'netmail' ) AND ( !array_key_exists( 'netmail', $this->areaList ) ) ) {
// $netmail = true;
// if ($toAka) {
// foreach ($this->user['groups'] as $k => $g) {
// if ((explode(':', $g)[0] == explode(':', $toAka)[0]) AND ($this->areaName == 'netmail')) {
// $fromAka = $g;
// $domain = $echo = $k;
// }
// }
// }
// }
// So I replaced it with this for now
if ($this->areaName == 'netmail') {
$netmail = true;
}
$jam = new jam();
if ($replyId != NULL) {
$header = $jam->getMsgHeader($this->areaList[$this->areaName]['filename'], $jam->getLastNumActive($this->areaList[$this->areaName]['filename']) - 1 - $replyId, 1);
$replyId = $header[0]['MSGID'][0];
}
foreach ($this->user['groups'] as $k => $g) {
if ($defaultAka == false) $defaultAka = $g;
if (!$fromAka) {
if ($toAka) {
if ((explode(':', $g)[0] == explode(':', $toAka)[0]) AND ($fromAka == false)) {
$fromAka = $g;
$domain = $k;
}
} elseif ($k == $this->areaList[$this->areaName]['group']) {
$fromAka = $g;
$domain = $k;
}
}
}
if ($fromAka == false) $fromAka = $defaultAka;
$origin = $origin ? $origin : $this->user['origin'];
$tearline = $tearline ? $tearline : 'webJAM v' . VERSION;
$message .= '\n\n---' . $tearline . '\n * Origin: ' . substr($origin, 0, 65 - strlen($fromAka)) . ' (' . $fromAka . ')\n';
if ($netmail == true) {
echo $jam->saveMessage($this->areaList[$this->areaName]['filename'], $this->user['realname'], $fromAka, $toName, $toAka, $subject, time(), time(), time(), $message, $domain, $replyId, array(
'MSG_LOCAL',
'MSG_PRIVATE',
'MSG_TYPENET'
));
if ($this->config['semaphores']['netscan'] != false) touch($this->config['semaphores']['netscan']);
} elseif ($this->areaName == 'netmail') {
$ret = $jam->saveMessage($this->areaList[$this->areaName]['filename'], $this->user['realname'], $fromAka, $toName, $toAka, $subject, time(), time(), time(), $message, $domain, $replyId, array(
'MSG_LOCAL',
'MSG_PRIVATE',
'MSG_TYPENET'
));
if ($ret) echo 'netmail';
if ($this->config['semaphores']['netscan'] != false) touch($this->config['semaphores']['netscan']);
} else {
echo $jam->saveMessage($this->areaList[$this->areaName]['filename'], $this->user['realname'], $fromAka, $toName, false, $subject, time(), time(), time(), $message, $domain, $replyId);
if ($this->config['semaphores']['echoscan'] != false) touch($this->config['semaphores']['echoscan']);
}
}
/**
......@@ -108,7 +202,7 @@
}
$this->areaName = $this->apiCallPath[1];
$this->areaList = (new messagebase())->getAreaList();
$this->areaList = (new messagebase())->getAreaList();
if (!array_key_exists($this->areaName, $this->areaList)) {
throw new Exception('Area ' . $this->areaName . ' not found');
......@@ -128,6 +222,7 @@
}
if (array_key_exists(2, $this->apiCallPath)) {
// Do stuff if message id is defined
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
$this->getMessage();
}
......@@ -138,6 +233,7 @@
$this->deleteMessage();
}
} else {
// Do stuff if message id is not defined
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
$this->getList();
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment