Delete mail after processing and use psr-4 for autoload. fixes #17

pull/25/head
Alex Puiu 2022-05-17 11:52:56 +03:00
rodzic a809d456cd
commit 395d9ed512
6 zmienionych plików z 137 dodań i 105 usunięć

Wyświetl plik

@ -1,5 +1,10 @@
{
"require": {
"league/html-to-markdown": "^5.1"
},
"autoload": {
"psr-4": {
"Mail2Deck\\": "lib/"
}
}
}

Wyświetl plik

@ -11,4 +11,5 @@ define("MAIL_PASSWORD", "****");
define("DECODE_SPECIAL_CHARACTERS", true); //requires mbstring, if false special characters (like öäüß) won't be displayed correctly
define("ASSIGN_SENDER", true); // if true, sender will be assigned to card if has NC account
define("MAIL_NOTIFICATION", true); // if true, send notifications when a new card was created or an error occured
define("DELETE_MAIL_AFTER_PROCESSING", true);
?>

Wyświetl plik

@ -2,14 +2,16 @@
error_reporting(E_ERROR | E_PARSE);
require __DIR__ . '/vendor/autoload.php';
require_once("config.php");
require_once('lib/DeckClass.php');
require_once('lib/MailClass.php');
require_once('lib/ConvertToMD.php');
use Mail2Deck\MailClass;
use Mail2Deck\DeckClass;
use Mail2Deck\ConvertToMD;
$inbox = new MailClass();
$emails = $inbox->getNewMessages();
if ($emails)
if(!$emails) return; // nothing to do
for ($j = 0; $j < count($emails) && $j < 5; $j++) {
$structure = $inbox->fetchMessageStructure($emails[$j]);
$base64encode = false;
@ -114,5 +116,10 @@ if ($emails)
if(!$response) {
foreach($attNames as $attachment) unlink(getcwd() . "/attachments/" . $attachment);
}
//remove email after processing
if(DELETE_MAIL_AFTER_PROCESSING) {
$inbox->delete($emails[$j]);
}
}
?>

Wyświetl plik

@ -1,5 +1,7 @@
<?php
namespace Mail2Deck;
use League\HTMLToMarkdown\HtmlConverter;
class ConvertToMD {
@ -18,5 +20,3 @@ class ConvertToMD {
return $this->converter->convert($this->html);
}
}
?>

Wyświetl plik

@ -1,5 +1,10 @@
<?php
namespace Mail2Deck;
use stdClass;
use CURLFile;
class DeckClass {
private $responseCode;
@ -141,4 +146,3 @@ class DeckClass {
return false;
}
}
?>

Wyświetl plik

@ -1,5 +1,7 @@
<?php
namespace Mail2Deck;
class MailClass {
private $inbox;
@ -60,8 +62,8 @@ class MailClass {
);
if($response) {
$body = "<h1>A new card has been created on board <a href=\"" . NC_SERVER . "index.php/apps/deck/#/board/{$response->board}" . "\">{$response->boardTitle}</a>.</h1>
<p>Check out this <a href=\"" . NC_SERVER . "index.php/apps/deck/#/board/{$response->board}/card/{$response->id}" . "\">link</a> to see the newly created card.</p>
$body = "<h1>A new card has been created on board <a href=\"" . NC_SERVER . "/index.php/apps/deck/#/board/{$response->board}" . "\">{$response->boardTitle}</a>.</h1>
<p>Check out this <a href=\"" . NC_SERVER . "/index.php/apps/deck/#/board/{$response->board}/card/{$response->id}" . "\">link</a> to see the newly created card.</p>
<p>Card ID is {$response->id}</p>";
$subject = 'A new card has been created!';
} else {
@ -76,4 +78,17 @@ class MailClass {
mail($sender, $subject, $message, $headers);
}
/**
* Deletes a mail
*
* @param $email email id that you want to delete
*
* @return void
*/
public function delete(int $email)
{
imap_delete($this->inbox, $email);
imap_expunge($this->inbox);
}
}