This commit has been accessed 675 times via Git panel.
commit a15ccd7d4a452dc269aa8e857642139fdf341e75
tree 159152f0f024169af9664d18b8a7a9f95d7759ef
parent 2bd71e63e09a473768b11f37332fde2c8ba1b618
author Engels Antonio <engels@majcms.org> 1334331018 +0800
committer Engels Antonio <engels@majcms.org> 1334331018 +0800
Add simple Sieve filter frontend
diff --git a/index.php b/index.php
index 99477a0..c58da0d 100644
--- a/index.php
+++ b/index.php
@@ -7,7 +7,8 @@ $db_name = "kartero";
$db_user = "kartero";
$db_pass = "fr1ng3!";
-$mail_root = "/var/spool/kartero";
+$mail_root = "/kartero/mail";
+$mail_home = "/kartero/home";
/* feel free to hack the succeeding code to suit your needs (basic php and mysql skills required) */
@@ -1046,6 +1047,144 @@ if (isset($_SESSION['logged_uid'])) {
echo "</form>";
}
echo "</table>";
+
+ if (isset($mail_home) and !empty($mail_home)) {
+
+ $sivU = explode("@",$_SESSION['logged_uid']);
+ $sivN = $sivU[0];
+ $sivD = $sivU[1];
+ $sivP = "$mail_home/$sivD/{$sivN[0]}/$sivN";
+ $sivR = glob("$sivP/*.sieve",GLOB_NOSORT);
+
+ if (isset($_POST['sieveT']) and !empty($_POST['sieveT']) and isset($_POST['sieveV']) and !empty($_POST['sieveV']) and isset($_POST['sieveF']) and !empty($_POST['sieveF'])) {
+
+ $sieveT = strtolower(trim(strip_tags($_POST['sieveT'])));
+ $sieveV = trim($_POST['sieveV']);
+ $sieveF = imap_utf7_encode(trim(strip_tags($_POST['sieveF'])));
+
+ if ($sieveT == "from") {
+
+ $sieveP = "from";
+
+ $sieveV = extract_emails_from($sieveV);
+ $sieveV = $sieveV[0];
+
+ if ($sieveV != "") {
+ $sieveW = "require \"fileinto\"; if address :is \"from\" \"$sieveV\" { fileinto \"$sieveF\"; }";
+ }
+ }
+
+ if ($sieveT == "subject") {
+
+ $sieveP = "subj";
+
+ $sieveV = strip_tags($sieveV);
+
+ if ($sieveV != "") {
+ $sieveW = "require \"fileinto\"; if header :contains \"subject\" \"$sieveV\" { fileinto \"$sieveF\"; }";
+ }
+ }
+
+ if ($sieveW != ""){
+
+ if (count($sivR) > 0) {
+
+ foreach ($sivR as $sieveR) {
+
+ if (strtolower(trim(file_get_contents($sieveR))) != strtolower($sieveW)) {
+ continue;
+ }
+
+ unlink($sieveR);
+ }
+ }
+
+ $sieveP = "$sivP/{$sieveP}-" . date("YmdHis") . ".sieve";
+
+ $fp = fopen($sieveP,"w");
+ fwrite($fp,$sieveW);
+ fclose($fp);
+ }
+ }
+
+ if (isset($_POST['sieve']) and !empty($_POST['sieve'])) {
+
+ $sieve = strtolower(trim(strip_tags($_POST['sieve'])));
+
+ if (file_exists("$sivP/$sieve") and ($_POST['set'] == "sivD")) {
+ unlink("$sivP/$sieve");
+ }
+ }
+
+echo "<br><table border=\"0\" cellspacing=\"1\" cellpadding=\"1\" width=\"100%\">";
+echo "<form method=\"post\"><input type=\"hidden\" name=\"set\" value=\"sivA\"><tr>";
+echo "<td width=\"200\"><select class=\"input\" name=\"sieveT\"><option value=\"from\">If message is from</option><option value=\"subject\">If message subject contains</option></td>";
+echo "<td><input class=\"input\" type=\"text\" name=\"sieveV\" autocomplete=\"off\" required></td>";
+echo "<td><select class=\"input\" name=\"sieveF\"><option value=\"Trash\" selected>then move to Trash</option>";
+
+foreach ($usr_box as $sieveF) {
+
+ $sieveF = str_replace($host,"",$sieveF);
+
+ echo "<option value=\"$sieveF\">then move to $sieveF</option>";
+}
+
+echo "</select></td>";
+echo "<td><input type=\"submit\" value=\"add\"></td>";
+echo "</tr></form>";
+echo "</table>";
+
+ $sivR = glob("$sivP/*.sieve");
+
+ if (count($sivR) > 0) {
+
+ $sivW = 'require "include";';
+
+ echo "<br><table border=\"0\" cellspacing=\"1\" cellpadding=\"1\">";
+
+ foreach ($sivR as $sivS) {
+
+ $sivC = (explode('"',file_get_contents($sivS)));
+ $sivF = basename($sivS);
+
+ $sivW = $sivW . "\r\ninclude \"" . str_replace(".sieve","",$sivF) . '";';
+
+ echo "<form method=\"post\">";
+ echo "<input type=\"hidden\" name=\"set\" value=\"sivD\">";
+ echo "<input type=\"hidden\" name=\"sieve\" value=\"$sivF\">";
+ echo "<tr>";
+ echo "<td><input type=\"submit\" value=\"del\"></td>";
+
+ if ($sivC[3] == "from") {
+ echo "<td>If message is {$sivC[3]} {$sivC[5]} then move to {$sivC[7]}</td>";
+ }
+ else {
+ echo "<td>If message {$sivC[3]} contains {$sivC[5]} then move to {$sivC[7]}</td>";
+ }
+
+ echo "</tr>";
+ echo "</form>";
+ }
+
+ echo "</table>";
+
+ if ($sivW != file_get_contents("$sivP/.dovecot.sieve")) {
+
+ $fp = fopen("$sivP/.dovecot.sieve","w");
+ fwrite($fp,$sivW);
+ fclose($fp);
+ }
+ }
+ else {
+ if (file_exists("$sivP/.dovecot.sieve")) {
+ unlink("$sivP/.dovecot.sieve");
+ }
+
+ if (file_exists("$sivP/.dovecot.svbin")) {
+ unlink("$sivP/.dovecot.svbin");
+ }
+ }
+ }
}
else {
include("inbox.php");
diff --git a/read.php b/read.php
index 42f760a..643be77 100644
--- a/read.php
+++ b/read.php
@@ -388,7 +388,7 @@ if (isset($_POST['msg']) and !empty($_POST['msg']) and is_numeric($_POST['msg'])
$get_fromaddress = extract_emails_from($header->fromaddress);
$get_fromaddress = explode("@",$get_fromaddress[0]);
- if ($get_fromaddress[0] == "MAILER-DAEMON") {
+ if (strtoupper($get_fromaddress[0]) == "MAILER-DAEMON") {
echo nl2br(htmlentities(imap_body($mbox,$msgno,FT_UID)));
}
else {
tree 159152f0f024169af9664d18b8a7a9f95d7759ef
parent 2bd71e63e09a473768b11f37332fde2c8ba1b618
author Engels Antonio <engels@majcms.org> 1334331018 +0800
committer Engels Antonio <engels@majcms.org> 1334331018 +0800
Add simple Sieve filter frontend
diff --git a/index.php b/index.php
index 99477a0..c58da0d 100644
--- a/index.php
+++ b/index.php
@@ -7,7 +7,8 @@ $db_name = "kartero";
$db_user = "kartero";
$db_pass = "fr1ng3!";
-$mail_root = "/var/spool/kartero";
+$mail_root = "/kartero/mail";
+$mail_home = "/kartero/home";
/* feel free to hack the succeeding code to suit your needs (basic php and mysql skills required) */
@@ -1046,6 +1047,144 @@ if (isset($_SESSION['logged_uid'])) {
echo "</form>";
}
echo "</table>";
+
+ if (isset($mail_home) and !empty($mail_home)) {
+
+ $sivU = explode("@",$_SESSION['logged_uid']);
+ $sivN = $sivU[0];
+ $sivD = $sivU[1];
+ $sivP = "$mail_home/$sivD/{$sivN[0]}/$sivN";
+ $sivR = glob("$sivP/*.sieve",GLOB_NOSORT);
+
+ if (isset($_POST['sieveT']) and !empty($_POST['sieveT']) and isset($_POST['sieveV']) and !empty($_POST['sieveV']) and isset($_POST['sieveF']) and !empty($_POST['sieveF'])) {
+
+ $sieveT = strtolower(trim(strip_tags($_POST['sieveT'])));
+ $sieveV = trim($_POST['sieveV']);
+ $sieveF = imap_utf7_encode(trim(strip_tags($_POST['sieveF'])));
+
+ if ($sieveT == "from") {
+
+ $sieveP = "from";
+
+ $sieveV = extract_emails_from($sieveV);
+ $sieveV = $sieveV[0];
+
+ if ($sieveV != "") {
+ $sieveW = "require \"fileinto\"; if address :is \"from\" \"$sieveV\" { fileinto \"$sieveF\"; }";
+ }
+ }
+
+ if ($sieveT == "subject") {
+
+ $sieveP = "subj";
+
+ $sieveV = strip_tags($sieveV);
+
+ if ($sieveV != "") {
+ $sieveW = "require \"fileinto\"; if header :contains \"subject\" \"$sieveV\" { fileinto \"$sieveF\"; }";
+ }
+ }
+
+ if ($sieveW != ""){
+
+ if (count($sivR) > 0) {
+
+ foreach ($sivR as $sieveR) {
+
+ if (strtolower(trim(file_get_contents($sieveR))) != strtolower($sieveW)) {
+ continue;
+ }
+
+ unlink($sieveR);
+ }
+ }
+
+ $sieveP = "$sivP/{$sieveP}-" . date("YmdHis") . ".sieve";
+
+ $fp = fopen($sieveP,"w");
+ fwrite($fp,$sieveW);
+ fclose($fp);
+ }
+ }
+
+ if (isset($_POST['sieve']) and !empty($_POST['sieve'])) {
+
+ $sieve = strtolower(trim(strip_tags($_POST['sieve'])));
+
+ if (file_exists("$sivP/$sieve") and ($_POST['set'] == "sivD")) {
+ unlink("$sivP/$sieve");
+ }
+ }
+
+echo "<br><table border=\"0\" cellspacing=\"1\" cellpadding=\"1\" width=\"100%\">";
+echo "<form method=\"post\"><input type=\"hidden\" name=\"set\" value=\"sivA\"><tr>";
+echo "<td width=\"200\"><select class=\"input\" name=\"sieveT\"><option value=\"from\">If message is from</option><option value=\"subject\">If message subject contains</option></td>";
+echo "<td><input class=\"input\" type=\"text\" name=\"sieveV\" autocomplete=\"off\" required></td>";
+echo "<td><select class=\"input\" name=\"sieveF\"><option value=\"Trash\" selected>then move to Trash</option>";
+
+foreach ($usr_box as $sieveF) {
+
+ $sieveF = str_replace($host,"",$sieveF);
+
+ echo "<option value=\"$sieveF\">then move to $sieveF</option>";
+}
+
+echo "</select></td>";
+echo "<td><input type=\"submit\" value=\"add\"></td>";
+echo "</tr></form>";
+echo "</table>";
+
+ $sivR = glob("$sivP/*.sieve");
+
+ if (count($sivR) > 0) {
+
+ $sivW = 'require "include";';
+
+ echo "<br><table border=\"0\" cellspacing=\"1\" cellpadding=\"1\">";
+
+ foreach ($sivR as $sivS) {
+
+ $sivC = (explode('"',file_get_contents($sivS)));
+ $sivF = basename($sivS);
+
+ $sivW = $sivW . "\r\ninclude \"" . str_replace(".sieve","",$sivF) . '";';
+
+ echo "<form method=\"post\">";
+ echo "<input type=\"hidden\" name=\"set\" value=\"sivD\">";
+ echo "<input type=\"hidden\" name=\"sieve\" value=\"$sivF\">";
+ echo "<tr>";
+ echo "<td><input type=\"submit\" value=\"del\"></td>";
+
+ if ($sivC[3] == "from") {
+ echo "<td>If message is {$sivC[3]} {$sivC[5]} then move to {$sivC[7]}</td>";
+ }
+ else {
+ echo "<td>If message {$sivC[3]} contains {$sivC[5]} then move to {$sivC[7]}</td>";
+ }
+
+ echo "</tr>";
+ echo "</form>";
+ }
+
+ echo "</table>";
+
+ if ($sivW != file_get_contents("$sivP/.dovecot.sieve")) {
+
+ $fp = fopen("$sivP/.dovecot.sieve","w");
+ fwrite($fp,$sivW);
+ fclose($fp);
+ }
+ }
+ else {
+ if (file_exists("$sivP/.dovecot.sieve")) {
+ unlink("$sivP/.dovecot.sieve");
+ }
+
+ if (file_exists("$sivP/.dovecot.svbin")) {
+ unlink("$sivP/.dovecot.svbin");
+ }
+ }
+ }
}
else {
include("inbox.php");
diff --git a/read.php b/read.php
index 42f760a..643be77 100644
--- a/read.php
+++ b/read.php
@@ -388,7 +388,7 @@ if (isset($_POST['msg']) and !empty($_POST['msg']) and is_numeric($_POST['msg'])
$get_fromaddress = extract_emails_from($header->fromaddress);
$get_fromaddress = explode("@",$get_fromaddress[0]);
- if ($get_fromaddress[0] == "MAILER-DAEMON") {
+ if (strtoupper($get_fromaddress[0]) == "MAILER-DAEMON") {
echo nl2br(htmlentities(imap_body($mbox,$msgno,FT_UID)));
}
else {