<?php
/*
This file is part of Thomas Bley's moregroupware webmail2/calendar2/admin2 module. (tb-mgw)

More information:
-----------------

Simple Groupware Solutions Thomas Bley
Fichtenstr. 23
Germany, 85640 Putzbrunn

Contact:
--------

info@simple-groupware.de

http://www.simple-groupware.de


Copyright 2002-2003 Thomas Bley
tb-mgw is distributed under the terms of the GNU General Public License 

tb-mgw is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

tb-mgw is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with tb-mgw; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

// Fetchmail-inc
// Moregroupware.org


function relocate($target,$theurl,$waittime) {
  if ($waittime==0) {
    echo '
	  <script language="JavaScript">
	  '.$target.'="'.$theurl.'";
	  </script>
	';
  } else {
	echo '
	  <script language="JavaScript">
	  	setTimeout("reloadit()",'.$waittime.');
	  	function reloadit () {
          '.$target.'="'.$theurl.'";
	  	}
      </script>
	';
  }
}

function is_spam2($fromaddress,$match) {
  $spam = false;
  $structure = Mail_RFC822::parseAddressList(strtolower(trim($fromaddress))." (abc)", '', TRUE);
  $match = strtolower(trim($match));
  if ($match!="") {
	if (strpos("#".$match, "@")>0) {
	  if ($match[0]=="%" and "%@".$structure[0]->host==$match) {
		$spam = true;
	  } elseif ($structure[0]->mailbox."@".$structure[0]->host==$match) {
		$spam = true;
	  }
    } elseif ($match[0]=="%") {
	  $match = substr($match,1);
	  if (strpos("#".$structure[0]->host, $match)>1) {
		$spam = true;
	  }
	}
  }
  return $spam;
}

/*
function is_spam($fromaddress,$subject) {
  global $MGW;
  $spam = false;
  $structure = Mail_RFC822::parseAddressList(strtolower(trim($fromaddress))." (abc)", '', TRUE);
  $subject = strtolower(trim($fromaddress));

  if ($MGW->settings["wm2_antispam"]!="") {
	$spams = explode("\n",$MGW->settings["wm2_antispam"]);
	foreach ($spams as $spam) {
	  $trimy = strtolower(trim($spam));
	  if (strlen($trimy) != 0) {
		if (!strpos($trimy, "@") === false) {
		  if ($trimy[0]=="%" and "%@".$structure[0]->host==$trimy) {
			$spam = true;
			break;
	      } elseif ($structure[0]->mailbox."@".$structure[0]->host==$trimy) {
			$spam = true;
			break;
	      }
	    } elseif (isset($trimy) and $trimy!="" and $trimy[0]=="%") {
		  $trimy = substr($trimy,1);
		  if (!strpos($structure[0]->host, $trimy) === false) {
			$spam = true;
			break;
	      }
		}
      }
	}
  }
  if (isset($MGW->settings["wm2_antispam_subject"]) and $MGW->settings["wm2_antispam_subject"]!="") {
	$spams = explode("\n",$MGW->settings["wm2_antispam_subject"]);
	foreach ($spams as $spam) {
	  $trimy = strtolower(trim($spam));
	  if (strlen($trimy) != 0) {
		if (!strpos($subject, $trimy) === false) {
		  $spam = true;
		  break;
		}
      }
	}
  }
  return $spam;
}
*/
		
function is_spam_admin($fromaddress,$subject) {
  global $MGW;
  $spam_b = false;
  $structure = Mail_RFC822::parseAddressList(strtolower(trim($fromaddress))." (abc)", '', TRUE);
  $subject = strtolower(trim($fromaddress));

  if ($MGW->settings["wm2_antispam_admin"]!="") {
	$spams = explode("\n",$MGW->settings["wm2_antispam_admin"]);
	foreach ($spams as $spam) {
	  $trimy = strtolower(trim($spam));
	  if (strlen($trimy) != 0) {
		if (!strpos($trimy, "@") === false) {
		  if ($trimy[0]=="%" and "%@".$structure[0]->host==$trimy) {
			$spam_b = true;
			break;
	      } elseif ($structure[0]->mailbox."@".$structure[0]->host==$trimy) {
			$spam_b = true;
			break;
	      }
	    } elseif (isset($trimy) and $trimy!="" and $trimy[0]=="%") {
		  $trimy = substr($trimy,1);
		  if (!strpos($structure[0]->host, $trimy) === false) {
			$spam_b = true;
			break;
	      }
		}
      }
	}
  }
  if (isset($MGW->settings["wm2_antispam_subject_admin"]) and $MGW->settings["wm2_antispam_subject_admin"]!="") {
	$spams = explode("\n",$MGW->settings["wm2_antispam_subject_admin"]);
	foreach ($spams as $spam) {
	  $trimy = strtolower(trim($spam));
	  if (strlen($trimy) != 0) {
		if (!strpos($subject, $trimy) === false) {
		  $spam_b = true;
		  break;
		}
      }
	}
  }
  return $spam_b;
}
		
function crowdfetcharr() {
  global $MGW,$conn,$fetchcount,$user_id,$username;
  
  $fetchcount = -1;
  $fetcharr = array();
  $havedone = false;
  $sql = "select * from mgw_webmail2_accounts where mailboxname!='' and user_id=".(int)$user_id;
  if(!$res = $conn->Execute($sql)) die(showSQLerror($sql, $conn->ErrorMsg(), __LINE__,__FILE__));
  while($row = $res->FetchRow()) {
	if ($row["mailboxname"]!="") {
	  if ($row["activated"]=="checked" and $row["servertype"]!="wm2_servertype_imap_only" and ($row["mailboxname"]!="default" || $MGW->username!="admin")) {
		if (!$havedone) {
		  $fetchcount = count($fetcharr);
  		  $havedone = true;
		}
	    $fetcharr[] = array($row["mailboxname"],"fetching ...","","0","","0","0","0");
	  } else {
	    $fetcharr[] = array($row["mailboxname"],"disabled","","0","","0","0","0");
	  }
    }
  }
  if (!isset($fetcharr)) { $fetcharr[] = array($hashmap["fetchmail_no_account"],"disabled","","0","","0","0","0");}
  return $fetcharr;
}

?>