kopia lustrzana https://github.com/newroco/mail2deck
Assign user to newly created card if has NC account.
rodzic
51e46c709f
commit
77f99de5bb
|
@ -8,4 +8,5 @@ define("MAIL_SERVER_PORT", "143");
|
|||
define("MAIL_USER", "incoming");
|
||||
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
|
||||
?>
|
||||
|
|
25
index.php
25
index.php
|
@ -2,15 +2,14 @@
|
|||
error_reporting(E_ERROR | E_PARSE);
|
||||
require_once("config.php");
|
||||
require_once('lib/DeckClass.php');
|
||||
require_once('lib/MailClass.php');
|
||||
|
||||
$inbox = imap_open("{" . MAIL_SERVER . ":" . MAIL_SERVER_PORT . MAIL_SERVER_FLAGS . "}INBOX", MAIL_USER, MAIL_PASSWORD)
|
||||
or die("can't connect:" . imap_last_error());
|
||||
|
||||
$emails = imap_search($inbox, 'UNSEEN');
|
||||
$inbox = new MailClass();
|
||||
$emails = $inbox->getNewMessages();
|
||||
|
||||
if ($emails)
|
||||
for ($j = 0; $j < count($emails) && $j < 5; $j++) {
|
||||
$structure = imap_fetchstructure($inbox, $emails[$j]);
|
||||
$structure = $inbox->fetchMessageStructure($emails[$j]);
|
||||
$attachments = array();
|
||||
$attNames = array();
|
||||
if (isset($structure->parts) && count($structure->parts)) {
|
||||
|
@ -34,7 +33,7 @@ if ($emails)
|
|||
}
|
||||
|
||||
if ($attachments[$i]['is_attachment']) {
|
||||
$attachments[$i]['attachment'] = imap_fetchbody($inbox, $emails[$j], $i+1);
|
||||
$attachments[$i]['attachment'] = $inbox->fetchMessageBody($emails[$j], $i+1);
|
||||
if ($structure->parts[$i]->encoding == 3) { // 3 = BASE64
|
||||
$attachments[$i]['attachment'] = base64_decode($attachments[$i]['attachment']);
|
||||
}
|
||||
|
@ -59,22 +58,24 @@ if ($emails)
|
|||
}
|
||||
}
|
||||
|
||||
$overview = imap_headerinfo($inbox, $emails[$j]);
|
||||
$overview = $inbox->headerInfo($emails[$j]);
|
||||
|
||||
$data = new stdClass();
|
||||
$data->title = DECODE_SPECIAL_CHARACTERS ? mb_decode_mimeheader($overview->subject) : $overview->subject;
|
||||
$data->type = "plain";
|
||||
$data->order = 999;
|
||||
if(count($attachments)) {
|
||||
$data->attachments = $attNames;
|
||||
$description = DECODE_SPECIAL_CHARACTERS ? quoted_printable_decode(imap_fetchbody($inbox, $emails[$j], 1.1)) : imap_fetchbody($inbox, $emails[$j], 1.1);
|
||||
$description = DECODE_SPECIAL_CHARACTERS ? quoted_printable_decode($inbox->fetchMessageBody($emails[$j], 1.1)) : $inbox->fetchMessageBody($emails[$j], 1.1);
|
||||
} else {
|
||||
$description = DECODE_SPECIAL_CHARACTERS ? quoted_printable_decode(imap_fetchbody($inbox, $emails[$j], 1)) : imap_fetchbody($inbox, $emails[$j], 1);
|
||||
$description = DECODE_SPECIAL_CHARACTERS ? quoted_printable_decode($inbox->fetchMessageBody($emails[$j], 1)) : $inbox->fetchMessageBody($emails[$j], 1);
|
||||
}
|
||||
$data->description = $description;
|
||||
$mailSender = new stdClass();
|
||||
$mailSender->userId = $overview->from[0]->mailbox;
|
||||
$mailSender = 'alex.puiu';
|
||||
|
||||
$newcard = new DeckClass();
|
||||
$newcard->addCard($data);
|
||||
$newcard->addCard($data, $mailSender);
|
||||
}
|
||||
|
||||
imap_close($inbox);
|
||||
?>
|
||||
|
|
|
@ -15,13 +15,14 @@ class DeckClass {
|
|||
CURLOPT_FOLLOWLOCATION => true,
|
||||
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
|
||||
CURLOPT_CUSTOMREQUEST => $request,
|
||||
CURLOPT_POSTFIELDS => (array) $data,
|
||||
CURLOPT_HTTPHEADER => array(
|
||||
'Authorization: Basic ' . base64_encode(NC_USER . ':' . NC_PASSWORD),
|
||||
'OCS-APIRequest: true',
|
||||
),
|
||||
));
|
||||
|
||||
if($request === 'POST') curl_setopt($curl, CURLOPT_POSTFIELDS, (array) $data);
|
||||
|
||||
$response = curl_exec($curl);
|
||||
$err = curl_error($curl);
|
||||
|
||||
|
@ -62,12 +63,15 @@ class DeckClass {
|
|||
return $boardStack;
|
||||
}
|
||||
|
||||
public function addCard($data) {
|
||||
public function addCard($data, $user) {
|
||||
$params = $this->getParameters($data->title);
|
||||
$data->title = $params->newTitle;
|
||||
$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($data->attachments) $this->addAttachments($card, $data->attachments);
|
||||
|
||||
return $card;
|
||||
|
@ -84,5 +88,18 @@ class DeckClass {
|
|||
unlink($file);
|
||||
}
|
||||
}
|
||||
|
||||
public function assignUser($card, $mailUser)
|
||||
{
|
||||
$board = $this->apiCall("GET", NC_SERVER . "/index.php/apps/deck/api/v1.0/boards/{$card->board}");
|
||||
$boardUsers = array_map(function ($user) { return $user->uid; }, $board->users);
|
||||
|
||||
foreach($boardUsers as $user) {
|
||||
if($user === $mailUser->userId) {
|
||||
$this->apiCall("PUT", NC_SERVER . "/index.php/apps/deck/api/v1.0/boards/{$card->board}/stacks/{$card->stack}/cards/{$card->id}/assignUser", $mailUser);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
|
||||
class MailClass {
|
||||
private $inbox;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->inbox = imap_open("{" . MAIL_SERVER . ":" . MAIL_SERVER_PORT . MAIL_SERVER_FLAGS . "}INBOX", MAIL_USER, MAIL_PASSWORD)
|
||||
or die("can't connect:" . imap_last_error());
|
||||
}
|
||||
|
||||
public function __destruct()
|
||||
{
|
||||
imap_close($this->inbox);
|
||||
}
|
||||
|
||||
public function getNewMessages() {
|
||||
return imap_search($this->inbox, 'UNSEEN');
|
||||
}
|
||||
|
||||
public function fetchMessageStructure($email) {
|
||||
return imap_fetchstructure($this->inbox, $email);
|
||||
}
|
||||
|
||||
public function fetchMessageBody($email, $section) {
|
||||
return imap_fetchbody($this->inbox, $email, $section);
|
||||
}
|
||||
|
||||
public function headerInfo($email) {
|
||||
return imap_headerinfo($this->inbox, $email);
|
||||
}
|
||||
|
||||
public function reply($sender, $response) {
|
||||
$to = $sender->mailbox . '@' . $sender->host;
|
||||
mail($to, 'your card has been created', 'card/board link.....');
|
||||
}
|
||||
}
|
Ładowanie…
Reference in New Issue