This commit has been accessed 712 times via Git panel.
commit 5cafce26d583593a5ef3f47a94d8682eb78437cc
tree 8b87a298133c61a3fd5532b215801feb8df398b5
parent 79fd5d1ff185b83da239a0fd5ab3ae7fbd7be334
author Engels Antonio <engels@majcms.org> 1362439828 +0800
committer Engels Antonio <engels@majcms.org> 1362439828 +0800
Add second pass file attach processor
diff --git a/pass2.php b/pass2.php
new file mode 100644
index 0000000..746ce36
--- /dev/null
+++ b/pass2.php
@@ -0,0 +1,64 @@
+<?php
+
+function pass2_extract($mbox, $msgno, $p, $partno, $path) {
+ $data = ($partno) ? imap_fetchbody($mbox, $msgno, $partno, FT_UID) : imap_body($mbox, $msgno, FT_UID);
+ if ($p->encoding == 4)
+ $data = quoted_printable_decode($data);
+ else if ($p->encoding == 3)
+ $data = base64_decode($data);
+ $params = array();
+ if ($p->parameters)
+ foreach ($p->parameters as $x)
+ $params[strtolower($x->attribute)] = $x->value;
+ if ($p->dparameters)
+ foreach ($p->dparameters as $x)
+ $params[strtolower($x->attribute)] = $x->value;
+ if ($params['filename'] || $params['name']) {
+ $partid = htmlentities($p->id, ENT_QUOTES, "UTF-8");
+ $filename = ($params['filename']) ? $params['filename'] : $params['name'];
+ $attachments[$filename] = $data;
+ $image[$key] = $filename;
+ }
+ if (count($attachments) > 0) {
+ if (!file_exists($path)) {
+ mkdir($path, 0700, 1);
+ }
+ foreach ($attachments as $key => $val) {
+ $files = glob("$path/*", GLOB_NOSORT);
+ if (count($files) > 0) {
+ $dup = "0";
+ foreach ($files as $file) {
+ if (file_get_contents($file) == $val) {
+ $dup++;
+ }
+ }
+ if (($dup == 0) and (mb_strlen($val,"8bit") > 0)) {
+ file_put_contents("$path/$key", $val);
+ }
+ }
+ else {
+ if (mb_strlen($val,"8bit") > 0) {
+ file_put_contents("$path/$key", $val);
+ }
+ }
+ unset($files);
+ }
+ }
+}
+
+function pass2_process($mbox, $msgno, $path) {
+ $attachments = array();
+ $s = imap_fetchstructure($mbox, $msgno, FT_UID);
+ if (!$s->parts) {
+ pass2_extract($mbox, $msgno, $s, 0, $path);
+ }
+ else {
+ foreach ($s->parts as $partno0 => $p) {
+ pass2_extract($mbox, $msgno, $p, $partno0 + 1, $path);
+ }
+ }
+}
+
+pass2_process($mbox, $msgno, $filePath);
+
+?>
diff --git a/read.php b/read.php
index 87553a9..39c27ae 100644
--- a/read.php
+++ b/read.php
@@ -444,6 +444,8 @@ if (isset($_POST['msg']) and !empty($_POST['msg']) and is_numeric($_POST['msg'])
}
}
+ include("pass2.php");
+
$bodyTEXT = get_part($mbox, $msgno, "TEXT/PLAIN");
$bodyHTML = get_part($mbox, $msgno, "TEXT/HTML");
tree 8b87a298133c61a3fd5532b215801feb8df398b5
parent 79fd5d1ff185b83da239a0fd5ab3ae7fbd7be334
author Engels Antonio <engels@majcms.org> 1362439828 +0800
committer Engels Antonio <engels@majcms.org> 1362439828 +0800
Add second pass file attach processor
diff --git a/pass2.php b/pass2.php
new file mode 100644
index 0000000..746ce36
--- /dev/null
+++ b/pass2.php
@@ -0,0 +1,64 @@
+<?php
+
+function pass2_extract($mbox, $msgno, $p, $partno, $path) {
+ $data = ($partno) ? imap_fetchbody($mbox, $msgno, $partno, FT_UID) : imap_body($mbox, $msgno, FT_UID);
+ if ($p->encoding == 4)
+ $data = quoted_printable_decode($data);
+ else if ($p->encoding == 3)
+ $data = base64_decode($data);
+ $params = array();
+ if ($p->parameters)
+ foreach ($p->parameters as $x)
+ $params[strtolower($x->attribute)] = $x->value;
+ if ($p->dparameters)
+ foreach ($p->dparameters as $x)
+ $params[strtolower($x->attribute)] = $x->value;
+ if ($params['filename'] || $params['name']) {
+ $partid = htmlentities($p->id, ENT_QUOTES, "UTF-8");
+ $filename = ($params['filename']) ? $params['filename'] : $params['name'];
+ $attachments[$filename] = $data;
+ $image[$key] = $filename;
+ }
+ if (count($attachments) > 0) {
+ if (!file_exists($path)) {
+ mkdir($path, 0700, 1);
+ }
+ foreach ($attachments as $key => $val) {
+ $files = glob("$path/*", GLOB_NOSORT);
+ if (count($files) > 0) {
+ $dup = "0";
+ foreach ($files as $file) {
+ if (file_get_contents($file) == $val) {
+ $dup++;
+ }
+ }
+ if (($dup == 0) and (mb_strlen($val,"8bit") > 0)) {
+ file_put_contents("$path/$key", $val);
+ }
+ }
+ else {
+ if (mb_strlen($val,"8bit") > 0) {
+ file_put_contents("$path/$key", $val);
+ }
+ }
+ unset($files);
+ }
+ }
+}
+
+function pass2_process($mbox, $msgno, $path) {
+ $attachments = array();
+ $s = imap_fetchstructure($mbox, $msgno, FT_UID);
+ if (!$s->parts) {
+ pass2_extract($mbox, $msgno, $s, 0, $path);
+ }
+ else {
+ foreach ($s->parts as $partno0 => $p) {
+ pass2_extract($mbox, $msgno, $p, $partno0 + 1, $path);
+ }
+ }
+}
+
+pass2_process($mbox, $msgno, $filePath);
+
+?>
diff --git a/read.php b/read.php
index 87553a9..39c27ae 100644
--- a/read.php
+++ b/read.php
@@ -444,6 +444,8 @@ if (isset($_POST['msg']) and !empty($_POST['msg']) and is_numeric($_POST['msg'])
}
}
+ include("pass2.php");
+
$bodyTEXT = get_part($mbox, $msgno, "TEXT/PLAIN");
$bodyHTML = get_part($mbox, $msgno, "TEXT/HTML");