From e616ebfffb407a4f4d2d0e7ba3c3ea19630f3950 Mon Sep 17 00:00:00 2001 From: Alex Puiu Date: Fri, 4 Feb 2022 14:57:16 +0200 Subject: [PATCH] reply to sender with newly created card, fixes #13 --- index.php | 7 +++++-- lib/DeckClass.php | 15 ++++++++++++--- lib/MailClass.php | 19 +++++++++++++++++-- 3 files changed, 34 insertions(+), 7 deletions(-) diff --git a/index.php b/index.php index 7f36eb5..10bf1b0 100644 --- a/index.php +++ b/index.php @@ -73,9 +73,12 @@ if ($emails) $data->description = $description; $mailSender = new stdClass(); $mailSender->userId = $overview->from[0]->mailbox; - $mailSender = 'alex.puiu'; $newcard = new DeckClass(); - $newcard->addCard($data, $mailSender); + $response = $newcard->addCard($data, $mailSender); + $mailSender->userId .= "@{$overview->from[0]->host}"; + if($response && ASSIGN_SENDER) { + $inbox->reply($mailSender->userId, $response); + } } ?> diff --git a/lib/DeckClass.php b/lib/DeckClass.php index b0486ee..f6b210d 100644 --- a/lib/DeckClass.php +++ b/lib/DeckClass.php @@ -1,6 +1,8 @@ responseCode = curl_getinfo($curl, CURLINFO_HTTP_CODE); curl_close($curl); if($err) echo "cURL Error #:" . $err; @@ -46,6 +49,7 @@ class DeckClass { foreach($boards as $board) { if(strtolower($board->title) == strtolower($boardFromMail)) { $boardId = $board->id; + $boardName = $board->title; } } @@ -59,6 +63,7 @@ class DeckClass { $boardStack->board = $boardId; $boardStack->stack = $stackId; $boardStack->newTitle = $params; + $boardStack->boardTitle = $boardName; return $boardStack; } @@ -69,10 +74,14 @@ class DeckClass { $card = $this->apiCall("POST", NC_SERVER . "/index.php/apps/deck/api/v1.0/boards/{$params->board}/stacks/{$params->stack}/cards", $data); $card->board = $params->board; $card->stack = $params->stack; - if(ASSIGN_SENDER) { - $this->assignUser($card, $user); + + if($this->responseCode == 200) { + if(ASSIGN_SENDER) $this->assignUser($card, $user); + if($data->attachments) $this->addAttachments($card, $data->attachments); + $card->boardTitle = $params->boardTitle; + } else { + return false; } - if($data->attachments) $this->addAttachments($card, $data->attachments); return $card; } diff --git a/lib/MailClass.php b/lib/MailClass.php index 438fc7f..9044b03 100644 --- a/lib/MailClass.php +++ b/lib/MailClass.php @@ -31,7 +31,22 @@ class MailClass { } public function reply($sender, $response) { - $to = $sender->mailbox . '@' . $sender->host; - mail($to, 'your card has been created', 'card/board link.....'); + $serverName = parse_url(NC_SERVER); + + $headers = array( + 'From' => 'no-reply@' . $serverName['host'], + 'MIME-Version' => '1.0', + 'Content-Type' => 'text/html' + ); + + $message = ""; + $message .= "You created a new issue on board {$response->boardTitle}."; + $message .= ""; + $message .= "

You created a new issue on board {$response->boardTitle}.

"; + $message .= "

Check out this board}/card/{$response->id}" . "\">link to see your newly created card.

"; + $message .= ""; + $message .= ""; + + mail($sender, 'An issue has been reported!', $message, $headers); } } \ No newline at end of file