pull/7/head
a11exandru 2019-12-13 20:22:40 +02:00
rodzic bf710f9bbd
commit ed1fb4e4b5
4 zmienionych plików z 98 dodań i 113 usunięć

Wyświetl plik

109
index.php
Wyświetl plik

@ -1,15 +1,102 @@
<?php
include_once("lib/newCard.php");
header("Refresh: 5");
?>
require_once("config.php");
require_once('lib/DeckClass.php');
header("Refresh: 120");
<!DOCTYPE html>
<html>
<head>
<title>Mail2Deck</title>
</head>
<body>
$inbox = imap_open("{" . MAIL_SERVER . "/imap/novalidate-cert}INBOX", MAIL_USER, MAIL_PASSWORD)
or die("can't connect:" . imap_last_error());
</body>
</html>
$emails = imap_search($inbox, 'UNSEEN');
if ($emails) rsort($emails);
$structure = imap_fetchstructure($inbox, $emails[0]);
$attachments = array();
if (isset($structure->parts) && count($structure->parts)) {
for ($i = 0; $i < count($structure->parts); $i++) {
$attachments[$i] = array(
'is_attachment' => false,
'filename' => '',
'name' => '',
'attachment' => ''
);
if ($structure->parts[$i]->ifdparameters) {
foreach ($structure->parts[$i]->dparameters as $object) {
if (strtolower($object->attribute) == 'filename') {
$attachments[$i]['is_attachment'] = true;
$attachments[$i]['filename'] = $object->value;
}
}
}
if ($structure->parts[$i]->ifparameters) {
foreach ($structure->parts[$i]->parameters as $object) {
if (strtolower($object->attribute) == 'name') {
$attachments[$i]['is_attachment'] = true;
$attachments[$i]['name'] = $object->value;
}
}
}
if ($attachments[$i]['is_attachment']) {
$attachments[$i]['attachment'] = imap_fetchbody($inbox, $emails[0], $i+1);
if ($structure->parts[$i]->encoding == 3) { // 3 = BASE64
$attachments[$i]['attachment'] = base64_decode($attachments[$i]['attachment']);
}
elseif ($structure->parts[$i]->encoding == 4) { // 4 = QUOTED-PRINTABLE
$attachments[$i]['attachment'] = quoted_printable_decode($attachments[$i]['attachment']);
}
}
}
}
for ($i = 1; $i < count($attachments); $i++) {
if ($attachments[$i]['is_attachment'] == 1) {
$filename = $attachments[$i]['name'];
if (empty($filename)) $filename = $attachments[$i]['filename'];
$fp = fopen("./attachments/" . $filename, "w+");
fwrite($fp, $attachments[$i]['attachment']);
fclose($fp);
}
}
$hasAttachment = false;
for ($i = 0; $i < count($attachments); $i++) {
if ($attachments[$i]['is_attachment'] != '') {
$hasAttachment = true;
}
}
if ($emails) {
$overview = imap_headerinfo($inbox, $emails[0]);
$toAddress = strrev($overview->toaddress);
if(preg_match('/@([^.]+)/', $toAddress, $m)) {
global $boardName;
$boardName = strrev($m[1]);
}
if ($hasAttachment) {
$message = imap_fetchbody($inbox, $emails[0], 1.1);
} else {
$message = imap_fetchbody($inbox, $emails[0], 1);
}
$mailData = new stdClass();
$mailData->mailSubject = $overview->subject;
$mailData->mailMessage = $message;
$mailData->from = $overview->from[0]->mailbox . '@' . $overview->from[0]->host;
$newcard = new DeckClass();
$newcard->getParameters();
$newcard->addCard($data);
if ($hasAttachment) {
for ($i = 1; $i <= count($attachments); $i++) {
$mailData->fileAttached[$i] = $attachments[$i]['name'];
}
$newcard->addAttachment($data);
}
} else {
echo "no mail arrived";
}
imap_close($inbox);
?>

Wyświetl plik

@ -1,9 +1,7 @@
<?php
include_once("../config.php");
class DeckClass {
protected function apiCall($request, $endpoint, $data){
set_time_limit(0);
$curl = curl_init();
$headers = [

Wyświetl plik

@ -1,100 +0,0 @@
<?php
require_once('DeckClass.php');
$inbox = imap_open("{" . MAIL_SERVER . "/imap/novalidate-cert}INBOX", MAIL_USER, MAIL_PASSWORD)
or die("can't connect:" . imap_last_error());
$emails = imap_search($inbox, 'UNSEEN');
rsort($emails);
$structure = imap_fetchstructure($inbox, $emails[0]);
$attachments = array();
if (isset($structure->parts) && count($structure->parts)) {
for ($i = 0; $i < count($structure->parts); $i++) {
$attachments[$i] = array(
'is_attachment' => false,
'filename' => '',
'name' => '',
'attachment' => ''
);
if ($structure->parts[$i]->ifdparameters) {
foreach ($structure->parts[$i]->dparameters as $object) {
if (strtolower($object->attribute) == 'filename') {
$attachments[$i]['is_attachment'] = true;
$attachments[$i]['filename'] = $object->value;
}
}
}
if ($structure->parts[$i]->ifparameters) {
foreach ($structure->parts[$i]->parameters as $object) {
if (strtolower($object->attribute) == 'name') {
$attachments[$i]['is_attachment'] = true;
$attachments[$i]['name'] = $object->value;
}
}
}
if ($attachments[$i]['is_attachment']) {
$attachments[$i]['attachment'] = imap_fetchbody($inbox, $emails[0], $i+1);
if ($structure->parts[$i]->encoding == 3) { // 3 = BASE64
$attachments[$i]['attachment'] = base64_decode($attachments[$i]['attachment']);
}
elseif ($structure->parts[$i]->encoding == 4) { // 4 = QUOTED-PRINTABLE
$attachments[$i]['attachment'] = quoted_printable_decode($attachments[$i]['attachment']);
}
}
}
}
for ($i = 1; $i < count($attachments); $i++) {
if ($attachments[$i]['is_attachment'] == 1) {
$filename = $attachments[$i]['name'];
if (empty($filename)) $filename = $attachments[$i]['filename'];
$fp = fopen("./attachments/" . $filename, "w+");
fwrite($fp, $attachments[$i]['attachment']);
fclose($fp);
}
}
$hasAttachment = false;
for ($i = 0; $i < count($attachments); $i++) {
if ($attachments[$i]['is_attachment'] != '') {
$hasAttachment = true;
}
}
if ($emails) {
$overview = imap_headerinfo($inbox, $emails[0]);
$toAddress = strrev($overview->toaddress);
if(preg_match('/@([^.]+)/', $toAddress, $m)) {
global $boardName;
$boardName = strrev($m[1]);
}
if ($hasAttachment) {
$message = imap_fetchbody($inbox, $emails[0], 1.1);
} else {
$message = imap_fetchbody($inbox, $emails[0], 1);
}
$mailData = new stdClass();
$mailData->mailSubject = $overview->subject;
$mailData->mailMessage = $message;
$mailData->from = $overview->from[0]->mailbox . '@' . $overview->from[0]->host;
$newcard = new DeckClass();
$newcard->getParameters();
$newcard->addCard($data);
if ($hasAttachment) {
for ($i = 1; $i <= count($attachments); $i++) {
$mailData->fileAttached[$i] = $attachments[$i]['name'];
}
$newcard->addAttachment($data);
}
} else {
echo "no mail arrived";
}
imap_close($inbox);
?>