This commit has been accessed 570 times via Git panel.
commit a056ad97059351db4b020c2d2108e5fc24cafb01
tree 1cc957182985f67f7d33ba6b8b539ac90e77e766
parent 982c3a55de4be55368144fb742c6013030559b73
author Engels Antonio <engels@majcms.org> 1334574339 +0800
committer Engels Antonio <engels@majcms.org> 1334574339 +0800
Add retroactive filtering on Sieve rule creation
diff --git a/core.php b/core.php
index 791b31f..1edec68 100644
--- a/core.php
+++ b/core.php
@@ -136,7 +136,7 @@ function get_part($stream, $msg_number, $mime_type, $structure = false, $part_nu
}
function extract_emails_from($string){
- preg_match_all("/[\._a-zA-Z0-9-]+@[\._a-zA-Z0-9-]+/i", $string, $matches);
+ preg_match_all("/[\+\=\._a-zA-Z0-9-]+@[\._a-zA-Z0-9-]+/i", $string, $matches);
return $matches[0];
}
@@ -330,4 +330,54 @@ class EmailMessage {
}
}
+function kartero_sort_folders($host,$array) {
+
+ if (is_array($array)) {
+
+ if (in_array("{$host}INBOX",$array)) {
+ $inbox = array_search("{$host}INBOX",$array);
+ unset($array[$inbox]);
+ unset($inbox);
+ }
+
+ if (in_array("{$host}Sent",$array)) {
+ $sent = array_search("{$host}Sent",$array);
+ unset($array[$sent]);
+ }
+ else {
+ if ($sent) {
+ unset($sent);
+ }
+ }
+
+ if (in_array("{$host}Trash",$array)) {
+ $trash = array_search("{$host}Trash",$array);
+ unset($array[$trash]);
+ }
+ else {
+ if ($trash) {
+ unset($trash);
+ }
+ }
+
+ sort($array);
+
+ if ($trash) {
+ array_unshift($array,"{$host}Trash");
+ unset($trash);
+ }
+
+ if ($sent) {
+ array_unshift($array,"{$host}Sent");
+ unset($sent);
+ }
+
+ array_unshift($array,"{$host}INBOX");
+
+ reset($array);
+
+ return $array;
+ }
+}
+
?>
diff --git a/folders.php b/folders.php
index e5aef41..172f1b1 100644
--- a/folders.php
+++ b/folders.php
@@ -83,54 +83,10 @@ echo "</table></div>";
echo "<div style=\"height: 4px;\"></div>";
-$get_folders = imap_list($mbox, $host, "*");
+$get_folders = kartero_sort_folders($host,imap_list($mbox,$host,"*"));
if (is_array($get_folders)) {
- if (in_array("{$host}INBOX",$get_folders)) {
-
- $inbox = array_search("{$host}INBOX",$get_folders);
-
- unset($get_folders[$inbox]);
- unset($inbox);
- }
-
- if (in_array("{$host}Sent",$get_folders)) {
-
- $priv_sent = 1;
-
- $sent = array_search("{$host}Sent",$get_folders);
-
- unset($get_folders[$sent]);
- unset($sent);
- }
-
- if (in_array("{$host}Trash",$get_folders)) {
-
- $priv_trash = 1;
-
- $trash = array_search("{$host}Trash",$get_folders);
-
- unset($get_folders[$trash]);
- unset($trash);
- }
-
- sort($get_folders);
-
- if ($priv_trash == 1) {
- array_unshift($get_folders,"{$host}Trash");
- unset($priv_trash);
- }
-
- if ($priv_sent == 1) {
- array_unshift($get_folders,"{$host}Sent");
- unset($priv_sent);
- }
-
- array_unshift($get_folders,"{$host}INBOX");
-
- reset($get_folders);
-
echo "\n\n<div class=\"folders\"><table border=\"0\" cellspacing=\"1\" callpadding=\"2\">";
foreach ($get_folders as $get_folder) {
diff --git a/index.php b/index.php
index fab1074..029a8ca 100644
--- a/index.php
+++ b/index.php
@@ -1073,27 +1073,25 @@ if (isset($_SESSION['logged_uid'])) {
$sieveV = trim($_POST['sieveV']);
$sieveF = imap_utf7_encode(trim(strip_tags($_POST['sieveF'])));
- if ($sieveT == "from") {
-
- $sieveP = "from";
+ if ($sieveT == "cc") {
+ $sieveP = "cc";
+ }
- $sieveV = extract_emails_from($sieveV);
- $sieveV = $sieveV[0];
+ if ($sieveT == "to") {
+ $sieveP = "to";
+ }
- if ($sieveV != "") {
- $sieveW = "require \"fileinto\"; if address :is \"from\" \"$sieveV\" { fileinto \"$sieveF\"; }";
- }
+ if ($sieveT == "from") {
+ $sieveP = "from";
}
if ($sieveT == "subject") {
-
$sieveP = "subj";
-
$sieveV = strip_tags($sieveV);
+ }
- if ($sieveV != "") {
- $sieveW = "require \"fileinto\"; if header :contains \"subject\" \"$sieveV\" { fileinto \"$sieveF\"; }";
- }
+ if ($sieveV != "") {
+ $sieveW = "require \"fileinto\"; if header :contains \"$sieveT\" \"$sieveV\" { fileinto \"$sieveF\"; }";
}
if ($sieveW != ""){
@@ -1112,9 +1110,22 @@ if (isset($_SESSION['logged_uid'])) {
$sieveP = "$sivP/{$sieveP}-" . date("YmdHis") . ".sieve";
+ if (!file_exists($sivP)) {
+ mkdir($sivP,0700,true);
+ }
+
$fp = fopen($sieveP,"w");
fwrite($fp,$sieveW);
fclose($fp);
+
+ $sieveC = "$sieveT \"$sieveV\"";
+
+ $sieveO = (imap_search($mbox,$sieveC,SE_UID));
+
+ foreach ($sieveO as $sivO) {
+ imap_mail_move($mbox,$sivO,$sieveF,CP_UID);
+ imap_expunge($mbox);
+ }
}
}
@@ -1129,7 +1140,12 @@ if (isset($_SESSION['logged_uid'])) {
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 width=\"200\"><select class=\"input\" name=\"sieveT\">";
+ echo "<option value=\"subject\">If message subject contains</option>";
+ echo "<option value=\"from\">If message from contains</option>";
+ echo "<option value=\"to\">If message to contains</option>";
+ echo "<option value=\"cc\">If message cc contains</option>";
+ echo "</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>";
@@ -1165,14 +1181,7 @@ if (isset($_SESSION['logged_uid'])) {
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 "<td>If message {$sivC[3]} contains {$sivC[5]} then move to {$sivC[7]}</td>";
echo "</tr>";
echo "</form>";
}
diff --git a/search.php b/search.php
index cebc75e..671054a 100644
--- a/search.php
+++ b/search.php
@@ -6,13 +6,10 @@ if (!isset($_SESSION['logged_uid']) or !isset($_SESSION['logged_lvl']) or !isset
exit;
}
-$search_folders = imap_list($mbox,$host,"*");
+$search_folders = kartero_sort_folders($host,imap_list($mbox,$host,"*"));
if (is_array($search_folders)) {
- reset($search_folders);
- sort($search_folders);
-
echo "<title>Kartero - Search $folder</title>";
echo "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"800\"><tr>";
tree 1cc957182985f67f7d33ba6b8b539ac90e77e766
parent 982c3a55de4be55368144fb742c6013030559b73
author Engels Antonio <engels@majcms.org> 1334574339 +0800
committer Engels Antonio <engels@majcms.org> 1334574339 +0800
Add retroactive filtering on Sieve rule creation
diff --git a/core.php b/core.php
index 791b31f..1edec68 100644
--- a/core.php
+++ b/core.php
@@ -136,7 +136,7 @@ function get_part($stream, $msg_number, $mime_type, $structure = false, $part_nu
}
function extract_emails_from($string){
- preg_match_all("/[\._a-zA-Z0-9-]+@[\._a-zA-Z0-9-]+/i", $string, $matches);
+ preg_match_all("/[\+\=\._a-zA-Z0-9-]+@[\._a-zA-Z0-9-]+/i", $string, $matches);
return $matches[0];
}
@@ -330,4 +330,54 @@ class EmailMessage {
}
}
+function kartero_sort_folders($host,$array) {
+
+ if (is_array($array)) {
+
+ if (in_array("{$host}INBOX",$array)) {
+ $inbox = array_search("{$host}INBOX",$array);
+ unset($array[$inbox]);
+ unset($inbox);
+ }
+
+ if (in_array("{$host}Sent",$array)) {
+ $sent = array_search("{$host}Sent",$array);
+ unset($array[$sent]);
+ }
+ else {
+ if ($sent) {
+ unset($sent);
+ }
+ }
+
+ if (in_array("{$host}Trash",$array)) {
+ $trash = array_search("{$host}Trash",$array);
+ unset($array[$trash]);
+ }
+ else {
+ if ($trash) {
+ unset($trash);
+ }
+ }
+
+ sort($array);
+
+ if ($trash) {
+ array_unshift($array,"{$host}Trash");
+ unset($trash);
+ }
+
+ if ($sent) {
+ array_unshift($array,"{$host}Sent");
+ unset($sent);
+ }
+
+ array_unshift($array,"{$host}INBOX");
+
+ reset($array);
+
+ return $array;
+ }
+}
+
?>
diff --git a/folders.php b/folders.php
index e5aef41..172f1b1 100644
--- a/folders.php
+++ b/folders.php
@@ -83,54 +83,10 @@ echo "</table></div>";
echo "<div style=\"height: 4px;\"></div>";
-$get_folders = imap_list($mbox, $host, "*");
+$get_folders = kartero_sort_folders($host,imap_list($mbox,$host,"*"));
if (is_array($get_folders)) {
- if (in_array("{$host}INBOX",$get_folders)) {
-
- $inbox = array_search("{$host}INBOX",$get_folders);
-
- unset($get_folders[$inbox]);
- unset($inbox);
- }
-
- if (in_array("{$host}Sent",$get_folders)) {
-
- $priv_sent = 1;
-
- $sent = array_search("{$host}Sent",$get_folders);
-
- unset($get_folders[$sent]);
- unset($sent);
- }
-
- if (in_array("{$host}Trash",$get_folders)) {
-
- $priv_trash = 1;
-
- $trash = array_search("{$host}Trash",$get_folders);
-
- unset($get_folders[$trash]);
- unset($trash);
- }
-
- sort($get_folders);
-
- if ($priv_trash == 1) {
- array_unshift($get_folders,"{$host}Trash");
- unset($priv_trash);
- }
-
- if ($priv_sent == 1) {
- array_unshift($get_folders,"{$host}Sent");
- unset($priv_sent);
- }
-
- array_unshift($get_folders,"{$host}INBOX");
-
- reset($get_folders);
-
echo "\n\n<div class=\"folders\"><table border=\"0\" cellspacing=\"1\" callpadding=\"2\">";
foreach ($get_folders as $get_folder) {
diff --git a/index.php b/index.php
index fab1074..029a8ca 100644
--- a/index.php
+++ b/index.php
@@ -1073,27 +1073,25 @@ if (isset($_SESSION['logged_uid'])) {
$sieveV = trim($_POST['sieveV']);
$sieveF = imap_utf7_encode(trim(strip_tags($_POST['sieveF'])));
- if ($sieveT == "from") {
-
- $sieveP = "from";
+ if ($sieveT == "cc") {
+ $sieveP = "cc";
+ }
- $sieveV = extract_emails_from($sieveV);
- $sieveV = $sieveV[0];
+ if ($sieveT == "to") {
+ $sieveP = "to";
+ }
- if ($sieveV != "") {
- $sieveW = "require \"fileinto\"; if address :is \"from\" \"$sieveV\" { fileinto \"$sieveF\"; }";
- }
+ if ($sieveT == "from") {
+ $sieveP = "from";
}
if ($sieveT == "subject") {
-
$sieveP = "subj";
-
$sieveV = strip_tags($sieveV);
+ }
- if ($sieveV != "") {
- $sieveW = "require \"fileinto\"; if header :contains \"subject\" \"$sieveV\" { fileinto \"$sieveF\"; }";
- }
+ if ($sieveV != "") {
+ $sieveW = "require \"fileinto\"; if header :contains \"$sieveT\" \"$sieveV\" { fileinto \"$sieveF\"; }";
}
if ($sieveW != ""){
@@ -1112,9 +1110,22 @@ if (isset($_SESSION['logged_uid'])) {
$sieveP = "$sivP/{$sieveP}-" . date("YmdHis") . ".sieve";
+ if (!file_exists($sivP)) {
+ mkdir($sivP,0700,true);
+ }
+
$fp = fopen($sieveP,"w");
fwrite($fp,$sieveW);
fclose($fp);
+
+ $sieveC = "$sieveT \"$sieveV\"";
+
+ $sieveO = (imap_search($mbox,$sieveC,SE_UID));
+
+ foreach ($sieveO as $sivO) {
+ imap_mail_move($mbox,$sivO,$sieveF,CP_UID);
+ imap_expunge($mbox);
+ }
}
}
@@ -1129,7 +1140,12 @@ if (isset($_SESSION['logged_uid'])) {
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 width=\"200\"><select class=\"input\" name=\"sieveT\">";
+ echo "<option value=\"subject\">If message subject contains</option>";
+ echo "<option value=\"from\">If message from contains</option>";
+ echo "<option value=\"to\">If message to contains</option>";
+ echo "<option value=\"cc\">If message cc contains</option>";
+ echo "</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>";
@@ -1165,14 +1181,7 @@ if (isset($_SESSION['logged_uid'])) {
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 "<td>If message {$sivC[3]} contains {$sivC[5]} then move to {$sivC[7]}</td>";
echo "</tr>";
echo "</form>";
}
diff --git a/search.php b/search.php
index cebc75e..671054a 100644
--- a/search.php
+++ b/search.php
@@ -6,13 +6,10 @@ if (!isset($_SESSION['logged_uid']) or !isset($_SESSION['logged_lvl']) or !isset
exit;
}
-$search_folders = imap_list($mbox,$host,"*");
+$search_folders = kartero_sort_folders($host,imap_list($mbox,$host,"*"));
if (is_array($search_folders)) {
- reset($search_folders);
- sort($search_folders);
-
echo "<title>Kartero - Search $folder</title>";
echo "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"800\"><tr>";