kopia lustrzana https://github.com/newroco/mail2deck
add up to 5 cards in a single run.
rodzic
ee7a7acac5
commit
5a5bc0c9f3
|
@ -1,5 +1,5 @@
|
|||
<?php
|
||||
define("NC_SERVER", "http://devnc.newro.co");
|
||||
define("NC_SERVER", "https://devnc.newro.co");
|
||||
define("NC_USER", "deckbot");
|
||||
define("NC_PASSWORD", "nCFCU7b8Hvz7tB4");
|
||||
define("MAIL_SERVER", "devnc.newro.co");
|
||||
|
|
154
index.php
154
index.php
|
@ -2,102 +2,100 @@
|
|||
error_reporting(E_ERROR | E_PARSE);
|
||||
require_once("config.php");
|
||||
require_once('lib/DeckClass.php');
|
||||
header("Refresh: 120");
|
||||
|
||||
$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');
|
||||
if ($emails) rsort($emails);
|
||||
$emails = imap_search($inbox, 'SEEN');
|
||||
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 ($emails)
|
||||
for ($j = 0; $j <= count($emails) && $j <= 4; $j++) {
|
||||
$structure = imap_fetchstructure($inbox, $emails[$j]);
|
||||
$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]->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[$j], $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'];
|
||||
|
||||
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;
|
||||
}
|
||||
$fp = fopen("./attachments/" . $filename, "w+");
|
||||
fwrite($fp, $attachments[$i]['attachment']);
|
||||
fclose($fp);
|
||||
}
|
||||
}
|
||||
|
||||
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']);
|
||||
$hasAttachment = false;
|
||||
for ($i = 0; $i < count($attachments); $i++) {
|
||||
if ($attachments[$i]['is_attachment'] != '') {
|
||||
$hasAttachment = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
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'];
|
||||
$overview = imap_headerinfo($inbox, $emails[$j]);
|
||||
$toAddress = strrev($overview->toaddress);
|
||||
if(preg_match('/@([^.]+)/', $toAddress, $m)) {
|
||||
global $boardName;
|
||||
$boardName = strrev($m[1]);
|
||||
}
|
||||
if ($hasAttachment) {
|
||||
$message = imap_fetchbody($inbox, $emails[$j], 1.1);
|
||||
} else {
|
||||
$message = imap_fetchbody($inbox, $emails[$j], 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);
|
||||
}
|
||||
$newcard->addAttachment($data);
|
||||
}
|
||||
} else {
|
||||
echo "no mail arrived";
|
||||
}
|
||||
|
||||
imap_close($inbox);
|
||||
?>
|
Ładowanie…
Reference in New Issue