mirror of
https://github.com/opensupports/opensupports.git
synced 2025-08-22 02:08:29 +02:00
* Mandatory Login BE and Ruby tests * registration handle and remove user-system setting * create specific paths to mandatory login changing * BE logic not allow turn off mandatory login without registratrion * fix github issues * Delete config['user-system-enabled']. * Add some tabulations. * Create MandatoryLoginReducer. * Replace 'user-system' to 'mandatory-login'. * Replace user-system toggle to mandatory-login checbox. * Add some button in the header. * Change onChange function mandatory login name. * Disabled checkbox when you should not change it. * Delete consolelog and some irrelevant lines. * Change name of mandatory login reducer. * Change style button in install step 1 * Change style button in install step 2 * Fix loading bug in submmit button. * Change style button in install step 5 * Change style button in install step 6 * Delete UserSystemEnabled in ticket viewer component. * Delete UserSystemEnabled in some files. * Delete onRetriveFail function in main view ticket page. * Replace user-system-enabled to mandatory-login in some files. * replace user-system-enabled to mandatory-login in install steps. * Fix style in dashboard-[Ccreate-ticket-page and dashboard-list-article-page. * Fix mandatory login issues Co-authored-by: LautaroCesso <lautaro_cesso@hotmail.com> Co-authored-by: Ivan Diaz <ivan@opensupports.com>
156 lines
5.0 KiB
PHP
Executable File
156 lines
5.0 KiB
PHP
Executable File
<?php
|
|
use Respect\Validation\Validator as DataValidator;
|
|
|
|
class EmailPollingController extends Controller {
|
|
const PATH = '/email-polling';
|
|
const METHOD = 'POST';
|
|
|
|
private $mailbox;
|
|
|
|
public function validations() {
|
|
return [
|
|
'permission' => 'any',
|
|
'requestData' => [
|
|
'token' => [
|
|
'validation' => DataValidator::notBlank()->length(1, 200),
|
|
'error' => ERRORS::INVALID_TOKEN
|
|
]
|
|
]
|
|
];
|
|
}
|
|
|
|
public function handler() {
|
|
throw new RequestException(ERRORS::NO_PERMISSION);
|
|
|
|
$commentController = new CommentController();
|
|
$createController = new CreateController();
|
|
$defaultLanguage = Setting::getSetting('language')->getValue();
|
|
$defaultDepartmentId = Department::getAll()->first()->id;
|
|
|
|
|
|
if(Controller::request('token') !== Setting::getSetting('imap-token')->getValue())
|
|
throw new RequestException(ERRORS::INVALID_TOKEN);
|
|
|
|
|
|
$this->mailbox = new \PhpImap\Mailbox(
|
|
Setting::getSetting('imap-host')->getValue(),
|
|
Setting::getSetting('imap-user')->getValue(),
|
|
Setting::getSetting('imap-pass')->getValue(),
|
|
'files/'
|
|
);
|
|
|
|
$errors = [];
|
|
$emails = $this->getLastEmails();
|
|
|
|
$session = Session::getInstance();
|
|
$oldSession = [
|
|
'userId' => $session->getUserId(),
|
|
'staff' => $session->getToken(),
|
|
'token' => $session->isStaffLogged(),
|
|
];
|
|
|
|
foreach($emails as $email) {
|
|
Controller::setDataRequester(function ($key) use ($email, $defaultDepartmentId, $defaultLanguage) {
|
|
switch ($key) {
|
|
case 'ticketNumber':
|
|
return $email->getTicketNumber();
|
|
case 'title':
|
|
return $email->getSubject();
|
|
case 'content':
|
|
return $email->getContent();
|
|
case 'departmentId':
|
|
return $defaultDepartmentId;
|
|
case 'language':
|
|
return $defaultLanguage;
|
|
case 'email':
|
|
return $email->getSender();
|
|
case 'name':
|
|
return $email->getSenderName();
|
|
}
|
|
|
|
return null;
|
|
});
|
|
/*
|
|
if($email->getAttachment()) {
|
|
$attachment = $email->getAttachment();
|
|
$_FILES['file'] = [
|
|
'name' => $attachment->name,
|
|
'type' => mime_content_type($attachment->filePath),
|
|
'tmp_name' => $attachment->filePath,
|
|
'error' => UPLOAD_ERR_OK,
|
|
'size' => filesize($attachment->filePath),
|
|
];
|
|
}
|
|
*/
|
|
|
|
try {
|
|
if($email->isReply()) {
|
|
if($email->getTicket()->authorToArray()['email'] === $email->getSender()) {
|
|
$session->clearSessionData();
|
|
$session->createTicketSession($email->getTicket()->ticketNumber);
|
|
|
|
$commentController->handler();
|
|
}
|
|
} else {
|
|
$createController->handler();
|
|
}
|
|
} catch(\Exception $e) {
|
|
$errors[] = [
|
|
'author' => $email->getSender(),
|
|
'ticketNumber' => $email->getTicketNumber(),
|
|
'error' => $e->__toString(),
|
|
];
|
|
}
|
|
|
|
unset($_FILES['file']);
|
|
}
|
|
|
|
$session->clearSessionData();
|
|
$session->setSessionData($oldSession);
|
|
|
|
$this->eraseAllEmails();
|
|
|
|
if(count($errors)) {
|
|
Response::respondError(ERRORS::EMAIL_POLLING, null, $errors);
|
|
} else {
|
|
Response::respondSuccess();
|
|
}
|
|
}
|
|
|
|
public function getLastEmails() {
|
|
$mailsIds = $this->mailbox->searchMailbox('ALL');
|
|
$emails = [];
|
|
sort($mailsIds);
|
|
|
|
foreach($mailsIds as $mailId) {
|
|
$mail = $this->mailbox->getMail($mailId);
|
|
$mailHeader = $this->mailbox->getMailHeader($mailId);
|
|
// $mailAttachment = count($mail->getAttachments()) ? current($mail->getAttachments()) : null;
|
|
|
|
$emails[] = new Email([
|
|
'fromAddress' => $mailHeader->fromAddress,
|
|
'fromName' => $mailHeader->fromName,
|
|
'subject' => $mailHeader->subject,
|
|
'content' => $mail->textPlain,
|
|
'file' => null,
|
|
]);
|
|
|
|
foreach($mail->getAttachments() as $attachment) {
|
|
unlink($attachment->filePath);
|
|
}
|
|
}
|
|
|
|
return $emails;
|
|
}
|
|
|
|
public function eraseAllEmails() {
|
|
$mailsIds = $this->mailbox->searchMailbox('ALL');
|
|
|
|
foreach($mailsIds as $mailId) {
|
|
$this->mailbox->deleteMail($mailId);
|
|
}
|
|
|
|
$this->mailbox->expungeDeletedMails();
|
|
}
|
|
}
|