Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // change your db connection information below
- $db_connection = mysql_pconnect('host', 'user', 'pass') or die ("nope");
- mysql_select_db('database') or die("Unable to select database");
- function words_match ($haystack, $needle_string, $all) {
- // $all means whether to find all needles or just one
- $needles = explode(" ", $needle_string);
- $total_needles = count ($needles);
- $matches = 0;
- foreach ($needles as $needle) {
- $pos=stripos($haystack, $needle);
- if ($pos!==false) {
- $matches = $matches+1;
- }
- }
- if ($matches == $total_needles && $all == true ) {
- // if all words have to be found and they have been found -> return true
- return true;
- }
- elseif ($matches > 0 && $all == false) {
- // if some words have to be found and some have -> return true
- return true;
- }
- else return false;
- }
- if ($_POST) {
- // get all filters
- $query = "SELECT * from filter";
- $result = mysql_query($query);
- // get relevant POST vars
- $from = $_POST['from'];
- $plain_text = $_POST['plain_text'];
- $subject = $_POST['subject'];
- while ($row = mysql_fetch_array($result)) {
- // determine wether a rule applies
- $a='';
- $b='';
- $c='';
- $d='';
- if ($row['in_from']!='') {
- if ($row['in_from'] == $from) {
- $a='x';
- } else { $a='-'; }
- }
- if ($row['in_subject']!='') {
- if (words_match($subject, $row['in_subject'], true)) {
- $b='x';
- } else { $b='-'; }
- }
- if ($row['in_haswords']!='') {
- if (words_match($plain_text, $row['in_haswords'], true)) {
- $c='x';
- } else { $c='-'; }
- }
- if ($row['in_doesnt_have']!='') {
- if (words_match($plain_text, $row['in_doesnt_have'], false)) {
- $d='x';
- } else { $d='-'; }
- }
- if ($a!='-' && $b!='-' && $c!='-' && $d!='x') {
- // success: a valid rule has been found, now do something with it
- $out_subject = $subject;
- if ($row['out_desc']!='') {
- $out_subject = $row['out_desc'];
- }
- if ($row['out_due_date']!='') {
- $out_subject .= ' ^'.$row['out_due_date'];
- }
- if ($row['out_prio']!='') {
- $out_subject .= ' !'.$row['out_prio'];
- }
- if ($row['out_list_tags']!='') {
- $tags = explode(" ",$row['out_list_tags']);
- foreach ($tags as $tag) {
- $out_subject .= ' #'.$tag;
- }
- }
- if ($row['out_estimate']!='') {
- $out_subject .= ' ='.$row['out_estimate'];
- }
- if ($row['out_location']!='') {
- $out_subject .= ' @'.$row['out_location'];
- }
- // forward email to RMilk with enriched subject
- echo $out_subject;
- //change your email below
- }
- }
- }
- // the form below allows you to manually experiment with the script
- echo "<form action='" . $_SERVER['PHP_SELF'] . "' method='post'>\n";
- echo "from:<input type='text' name='from' value=". $_POST['from'] ." size='25' align='left'><br>\n";
- echo "to:<input type='text' name='to' value=". $_POST['to'] ." size='25' align='left'><br>\n";
- echo "subject:<input type='text' name='subject' value=". $_POST['subject'] ." size='25' align='left'><br>\n";
- echo "plain_text:<input type='text' name='plain_text' value=". $_POST['plain_text'] ." size='25' align='left'><br>\n";
- echo "<input type='submit' name='submitted' value='submit'>\n";
- echo "</form>\n";
- ?>
Advertisement
Add Comment
Please, Sign In to add comment