<?php 
// legend_via_map.php
// RJM Programming
// October, 2016
// Return webpage contents
ini_set('max_execution_time', 60000); 
$cno = 0;
$debug = "";
  
  if (isset($_GET['getthisback']) || isset($_GET['andcleanup'])) {
     if (isset($_GET['getthisback'])) {
     if (!file_exists(str_replace('+',' ',urldecode($_GET['getthisback'])))) {
      echo "<html><body>Not found is " . str_replace('+',' ',urldecode($_GET['getthisback'])) . "</body></html>";
     } else {
      echo "<html><body><p id=pid>" . file_get_contents(str_replace('+',' ',urldecode($_GET['getthisback']))) . "</p></body></html>";
     }
     }
     if (isset($_GET['andcleanup'])) {
     foreach (glob('/tmp/bigmedia_*.txt') as $tfl) {
    $filemtime = filemtime($tfl);
    if (time() - $filemtime >= 172800) {
        unlink($tfl);
    }
     }
     }
     exit;
  }

function oururlencode($conte) {
  return str_replace("+","%20",urlencode($conte));
}

function strposa($haystack, $needles=array(), $offset=0) { // thanks to http://stackoverflow.com/questions/6284553/using-an-array-as-needles-in-strpos
        $chr = array();
        foreach($needles as $needle) {
                $res = strpos($haystack, $needle, $offset);
                if ($res !== false) $chr[$needle] = $res;
        }
        if(empty($chr)) return false;
        return min($chr);
}

function getheaders($contents, $mybod) {
        global $cno;
        $ftype = "media";
        if (strpos($contents, "<html") !== false || $mybod == " ") {
            $contents = str_replace('`', '"', str_replace("~", "'", str_replace("!!", "&", $contents)));
            $filename="slide_emoji_show.html";
            $ftype = "webpage";
    //echo "<!doctype html><html><head><scr" . "ipt type='text/javascript'> function aemail(ame) { window.top.location = ame.href; } </scr" . "ipt></head><body onload='document.getElementById(\"aemail\").click();'><a id='aemail' onclick=' if (navigator.userAgent.match(/Android/i)) { aemail(this); } ' href='mailto:" . urldecode($_GET['to']) . "?subject=" . oururlencode($filename) . "&body=" .  oururlencode($ftype) . str_replace("\\","\\" . "\\",$contents) . $mybod . "*" . "' title='Email' style='display:none;'></a></body></html>";
        } 
        $mybods=explode(";", $mybod);
        $defone = ""; //"Please see or download image (first) before any download and double clicking of image clickable and applicable web application below:";
        $eol = PHP_EOL;
        $headers="";
        if (isset($_GET['from'])) {
        if ($_GET['from'] != '') {
        $headers = 'From: ' . 'rmetcalfe@rjmprogramming.com.au' . $eol;
        $headers .= 'Reply-To: ' . urldecode($_GET['from']) . $eol;
        } else {
        $headers = 'From: ' . 'rmetcalfe@rjmprogramming.com.au' . $eol;
        $headers .= 'Reply-To: ' . 'rmetcalfe@rjmprogramming.com.au' . $eol;
        }
        } else {
        $headers = 'From: ' . 'rmetcalfe@rjmprogramming.com.au' . $eol;
        $headers .= 'Reply-To: ' . 'rmetcalfe@rjmprogramming.com.au' . $eol;
        }
        if (isset($_GET['cc'])) {
        if ($_GET['CC'] != '') {
        $headers .= 'CC: ' . urldecode($_GET['cc']) . $eol;
        }
        }
        if (isset($_GET['bcc'])) {
        if ($_GET['BCC'] != '') {
        $headers .= 'BCC: ' . urldecode($_GET['bcc']) . $eol;
        }
        } else if (isset($_POST['from'])) {
        if ($_POST['from'] != '') {
        $headers = 'From: ' . 'rmetcalfe@rjmprogramming.com.au' . $eol;
        $headers .= 'Reply-To: ' . urldecode($_POST['from']) . $eol;
        } else {
        $headers = 'From: ' . 'rmetcalfe@rjmprogramming.com.au' . $eol;
        $headers .= 'Reply-To: ' . 'rmetcalfe@rjmprogramming.com.au' . $eol;
        }
        } else {
        $headers = 'From: ' . 'rmetcalfe@rjmprogramming.com.au' . $eol;
        $headers .= 'Reply-To: ' . 'rmetcalfe@rjmprogramming.com.au' . $eol;
        }
        if (isset($_POST['cc'])) {
        if ($_POST['CC'] != '') {
        $headers .= 'CC: ' . urldecode($_POST['cc']) . $eol;
        }
        }
        if (isset($_POST['bcc'])) {
        if ($_POST['BCC'] != '') {
        $headers .= 'BCC: ' . urldecode($_POST['bcc']) . $eol;
        }
        }
        if ($contents != '') {
    	  date_default_timezone_set('Australia/Perth');
    	  // a random hash will be necessary to send mixed content
    	  $separator = md5(time());
          for ($icno=0; $icno<sizeof($mybods); $icno++) {
          
            if ($icno != 0) {
              $contents = @file_get_contents($mybods[$icno]);
            }

            if (trim($mybod) == "" && strpos($contents, "<html") !== false) {
            $filename="slide_emoji_show.html";
            $ftype = "webpage";
    //echo "<!doctype html><html><head><scr" . "ipt type='text/javascript'> function aemail(ame) { window.top.location = ame.href; } </scr" . "ipt></head><body onload='document.getElementById(\"aemail\").click();'><a id='aemail' onclick=' if (navigator.userAgent.match(/Android/i)) { aemail(this); } ' href='mailto:" . urldecode($_GET['to']) . "?subject=" . oururlencode($filename) . "&body=" .  oururlencode($ftype) . "' title='Email' style='display:none;'></a></body></html>";
            $plain = "plain"; //"html";
            $debug = "y";
            } else {
            $plain = "plain";
    		$fs = explode("/", $mybods[$icno]);
    		$filename = $fs[-1 + sizeof($fs)];
    		}
    		$content = chunk_split(base64_encode($contents));

    		$headers .= "MIME-Version: 1.0" . $eol;
    		$headers .= "Content-Type: multipart/mixed; boundary=\"" . $separator . "\"" . $eol . $eol;
    		$headers .= "Content-Transfer-Encoding: 7bit" . $eol;
    		$headers .= "This is a MIME encoded message." . $eol . $eol;

    		// message
    		$headers .= "--" . $separator . $eol;
    		$headers .= "Content-Type: text/" . $plain . "; charset=\"iso-8859-1\"" . $eol;
    		$headers .= "Content-Transfer-Encoding: 8bit" . $eol . $eol;

			if ($icno != 0) {
    		  $headers .= $defone . $eol . $eol;
    		} else {
    		  $headers .= "Please see attached " . $ftype . " file below:" . $eol . $eol;
    		}
            //ourpremail($tem, $mysubject, "", $headers . "--" . $separator . "--");

    		// attachment
    		$headers .= "--" . $separator . $eol;
    		$headers .= "Content-Type: application/octet-stream; name=\"" . $filename . "\"" . $eol;
    		$headers .= "Content-Transfer-Encoding: base64" . $eol;
    		$headers .= "Content-Disposition: attachment;filename=\"" . $filename . "\"" . $eol;
    		$headers .= $content . $eol . $eol;
    		$cno++;
    	 }
       }
       return $headers;
}

function ourpremail($ris, $ssis, $tis, $his) {
    global $okay, $debug;
    $xsis = $ssis;
    try {
       //file_put_contents("aaaaa.00aaa", $ris . " " . $xsis);
       //if ($debug != "") {
       //  mail("rmetcalfe15@gmail.com", $xsis, "My Body", $his);
       //}
       mail($ris, $xsis, $tis, $his);
    } catch (Exception $merr) {
      $okay = 0;
      if (file_exists(dirname(__FILE__) . "/mail.prob")) {
        file_put_contents(dirname(__FILE__) . "/mail.prob", file_get_contents(dirname(__FILE__) . "/mail.prob") . "\n\n" . date('l jS \of F Y h:i:s A') . " ... " . $merr->getMessage());
      } else {
        file_put_contents(dirname(__FILE__) . "/mail.prob", date('l jS \of F Y h:i:s A') . " ... " . $merr->getMessage());
      }
    }
}

  $find_media = array('.wav', '.m4a', '.m4v', '.mp4', '.mp3', '.mp2', '.bmp', '.tif', '.png', '.jpeg', 'jpg', '.gif', '.ogg', '.mov', '.flv');
  $cont = "";
  $delim = "";
  $ilist="";
  
  if (isset($_GET['url'])) $ilist=$_GET['url'];

  if (strpos($_SERVER['HTTP_REFERER'], "rjmprogramming.com.au") === false) {
    echo '';
  } else if ($ilist == "insectlist.html") {
    echo file_get_contents('/home/rjmprogr/insectlist.html');
  } else if ($ilist == "amphibianlist.php") {
    echo file_get_contents('/home/rjmprogr/amphibianlist.php');
  } else if (isset($_POST['to']) && isset($_POST['urlbig']) && isset($_POST['subject'])) {
    if ($_POST['to'] == '' && $_POST['subject'] == '' && $_POST['urlbig'] != '' && isset($_POST['bcc']) && isset($_POST['cc'])) {
      $vslook='';
      $vsind='0';
      if (strpos(('~' . $_POST['urlbig']), '~data') !== false) {
        if ($_POST['bcc'] == '') {
          foreach (glob('/tmp/bigmedia_*.txt') as $tfl) {
            //file_put_contents('xc.xc', '' . $tfl);
            if ($vslook == '') {
                $vslook=str_replace(' ','+',urldecode($_POST['urlbig']));
            }
            $versusind=explode('.', explode('bigmedia_', $tfl)[1])[0];
            if (isset($_POST['softlink']) && strpos($vslook, ';base64,') !== false) {
              if (file_get_contents($tfl) == base64_decode( explode(';base64,', $vslook)[1] )) {
                echo "<html><body><p id=pid style=display:none;>//www.rjmprogramming.com.au/" . basename($tfl) . "." . $_POST['softlink'] . "</p></body></html>";
                exit;
              }
            } else if (file_get_contents($tfl) == $vslook) {
              echo "<html><body><p id=pid style=display:none;>" . $tfl . "</p></body></html>";
              exit;
            }
            if (strlen($versusind) < strlen($vsind)) {
            //file_put_contents('xc1.xc1', '' . $versusind . 'vs' . $vsind . ' ' . $tfl);
              $vsind=$vsind;
            } else if (strlen($versusind) > strlen($vsind)) {
              $vsind='' . (1 + intval($versusind));
            //file_put_contents('xc2.xc2', '' . $versusind . 'vs' . $vsind . ' ' . $vsind);
            } else if ($versusind >= $vsind) {
              $vsind='' . (1 + intval($versusind));
            //file_put_contents('xc3.xc3', '' . $versusind . 'vs' . $vsind . ' ' . $vsind);
            }
    $filemtime = filemtime($tfl);
    if (time() - $filemtime >= 172800) {
        unlink($tfl);
    }
          }
            //file_put_contents('xc4.xc4', '' . $vsind);
          if (isset($_POST['softlink'])) {
          file_put_contents('/tmp/bigmedia_' . $vsind . '.txt', base64_decode( explode(';base64,', str_replace(' ','+',urldecode($_POST['urlbig'])))[1] ) );
          if (file_exists($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . "bigmedia_" . $vsind . ".txt." . $_POST['softlink'])) {
            unlink($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . "bigmedia_" . $vsind . ".txt." . $_POST['softlink']);
          }
          exec('ln -s /tmp/bigmedia_' . $vsind . '.txt ' . $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . "bigmedia_" . $vsind . ".txt." . $_POST['softlink']);
          echo "<html><body><p id=pid style=display:none;>//www.rjmprogramming.com.au/bigmedia_" . $vsind . ".txt." . $_POST['softlink'] . "</p></body></html>";
          } else {
          file_put_contents('/tmp/bigmedia_' . $vsind . '.txt', str_replace(' ','+',urldecode($_POST['urlbig'])));
          echo "<html><body><p id=pid style=display:none;>/tmp/bigmedia_" . $vsind . ".txt</p></body></html>";
          }
        } else {
          if (strpos(strtolower($_POST['urlbig'] . '~'), ('%e2%80%a6~')) !== false || strpos(strtolower(urldecode($_POST['urlbig']) . '~'), (urldecode('%e2%80%a6') . '~')) !== false || 1 == 1) {
             if (file_exists('/tmp/bigmedia_' . trim(str_replace('+',' ',urldecode($_POST['bcc']))) . '.txt')) {
                if ($_POST['cc'] == '1') {
                echo "<html><body onload=\" parent.document.getElementById('spareurlbig').value='" . file_get_contents('/tmp/bigmedia_' . $_POST['bcc'] . '.txt') . "';  parent.document.getElementById('spareurlbig" . $_POST['cc'] . "').value='" . file_get_contents('/tmp/bigmedia_' . $_POST['bcc'] . '.txt') . "'; \"><p id=pid style=display:none;>/tmp/bigmedia_" . trim(str_replace('+',' ',urldecode($_POST['bcc']))) . ".txt'</p></body></html>";
                } else if (strlen($_POST['cc']) <= 1) {
                echo "<html><body onload=\" parent.document.getElementById('spareurlbig" . $_POST['cc'] . "').value='" . file_get_contents('/tmp/bigmedia_' . $_POST['bcc'] . '.txt') . "'; \"><p id=pid style=display:none;>/tmp/bigmedia_" . trim(str_replace('+',' ',urldecode($_POST['bcc']))) . ".txt'</p></body></html>";
                } else {
                echo "<html><body onload=\" parent.document.getElementById('spareurlbig').value='" . file_get_contents('/tmp/bigmedia_' . $_POST['bcc'] . '.txt') . "'; \"><p id=pid style=display:none;>/tmp/bigmedia_" . trim(str_replace('+',' ',urldecode($_POST['bcc']))) . ".txt'</p></body></html>";
                }
             } else {
                foreach (glob('/tmp/bigmedia_*.txt') as $tfl) {
                   if ($vslook == '') {
                     $vslook=str_replace(' ','+',urldecode($_POST['urlbig']));
                   }
                   $thislook=file_get_contents($tfl);
                   if (strpos($thislook, substr($vslook,0,(-13 + strlen($vslook)))) !== false) {
                     if ($_POST['cc'] == '1') {
                     echo "<html><body onload=\" parent.document.getElementById('spareurlbig').value='" . $thislook . "';  parent.document.getElementById('spareurlbig" . $_POST['cc'] . "').value='" . $thislook . "'; \"><p id=pid style=display:none;>" . $thislook . "</p></body></html>";
                     } else if (strlen($_POST['cc']) <= 1) {
                     echo "<html><body onload=\" parent.document.getElementById('spareurlbig" . $_POST['cc'] . "').value='" . $thislook . "'; \"><p id=pid style=display:none;>" . $thislook . "</p></body></html>";
                     } else {
                     echo "<html><body onload=\" parent.document.getElementById('spareurlbig0').value='" . $thislook . "'; \"><p id=pid style=display:none;>" . $thislook . "</p></body></html>";
                     }
                   }
    $filemtime = filemtime($tfl);
    if (time() - $filemtime >= 172800) {
        unlink($tfl);
    }
                }
             }
          }
        }
      }
      exit;
    }
    $mybody=urldecode($_POST['urlbig']);
    $mysubject=urldecode($_POST['subject']);
    $myflist="";
    if (isset($_POST['url'])) {
    $f = strpos($_POST['url'], '%');
      if ($f === false) {
       if ($_POST['url'] != "") {
         $cont=@file_get_contents(str_replace("https:","http:",($_POST['url'])));
       } else if (strpos($mybody, "<html") !== false) {
         $cont=$mybody;
         $mybody = "Emoji Slideshow is as attached below.";
       }
       $myflist=($_POST['url']);
       if ($_POST['url'] != "") $delim = ";";
      } else {
       if ($_POST['url'] != "") {
         $cont=@file_get_contents(str_replace("https:","http:",urldecode($_POST['url'])));
       } else if (strpos($mybody, "<html") !== false) {
         $cont=$mybody;
         $mybody = "Emoji Slideshow is as attached below.";
       }
       $myflist=urldecode($_POST['url']);
       if ($_POST['url'] != "") $delim = ";";
      }
    }
    $myfiles=explode(";", $mybody);
    if (sizeof($myfiles) > 1) {
      for ($ii=1; $ii<sizeof($myfiles); $ii++) {
        $myone=explode("&", $myfiles[$ii]);
        if (strpos($myflist, $myone[0]) === false) {
          $myflist.=$delim .  $myone[0];
  $delim = ";";
          if ($cont == "") {
            $cont=@file_get_contents($myone[0]);
          }
        }
      }
    }
    if (isset($_POST['body'])) {
      $mysubject.=" " . urldecode($_POST['body']);
    } else if ($mybody != "Emoji Slideshow is as attached below.") {
      $mysubject.=" Please attach media file " . str_replace(";"," and ",str_replace("file://", "", $myflist));
    }
    if (strpos($_POST['to'], "@") === false || strlen($cont) == 0) {
    echo "<!doctype html><html><head><scr" . "ipt type='text/javascript'> function aemail(ame) { window.top.location = ame.href; } </scr" . "ipt></head><body onload='document.getElementById(\"aemail\").click();'><a id='aemail' onclick=' if (navigator.userAgent.match(/Android/i) || navigator.userAgent.match(/Firefox/i)) { aemail(this); } ' href='mailto:" . urldecode($_POST['to']) . "?subject=" . oururlencode($mysubject) . "&body=" .  oururlencode($mybody) . "' title='Email' style='display:none;'></a></body></html>";
    } else {
    if ($mybody == "Emoji Slideshow is as attached below.") $myflist = " ";
    //if ($mybody == "Emoji Slideshow is as attached below.") echo "<!doctype html><html><head><scr" . "ipt type='text/javascript'> function aemail(ame) { window.top.location = ame.href; } </scr" . "ipt></head><body onload='document.getElementById(\"aemail\").click();'><a id='aemail' onclick=' if (navigator.userAgent.match(/Android/i)) { aemail(this); } ' href='mailto:" . urldecode($_GET['to']) . "?subject=" . oururlencode($mysubject) . "&body=" .  oururlencode($cont) . "' title='Email' style='display:none;'></a></body></html>";
    ourpremail(urldecode($_POST['to']), $mysubject, $mybody, getheaders($cont, $myflist));
    }

  } else if (isset($_GET['to']) && isset($_GET['urlbig']) && isset($_GET['subject'])) {
    $mybody=urldecode($_GET['urlbig']);
    $mysubject=urldecode($_GET['subject']);
    $myflist="";
    if (isset($_GET['url'])) {
    $f = strpos($_GET['url'], '%');
      if ($f === false) {
       if ($_GET['url'] != "") $cont=@file_get_contents(str_replace("https:","http:",($_GET['url'])));
       $myflist=($_GET['url']);
  if ($_GET['url'] != "") $delim = ";";
      } else {
       if ($_GET['url'] != "") $cont=@file_get_contents(str_replace("https:","http:",urldecode($_GET['url'])));
  if ($_GET['url'] != "") $delim = ";";
       $myflist=urldecode($_GET['url']);
      }
    }
    $myfiles=explode(";", $mybody);
    if (sizeof($myfiles) > 1) {
      for ($ii=1; $ii<sizeof($myfiles); $ii++) {
        $myone=explode("&", $myfiles[$ii]);
        if (strpos($myflist, $myone[0]) === false) {
          $myflist.=$delim .  $myone[0];
  $delim = ";";
          if ($cont == "") $cont=@file_get_contents($myone[0]);
        }
      }
    }
    if (isset($_GET['body'])) {
      $mysubject.=" " . urldecode($_GET['body']);
    } else {
      $mysubject.=" Please attach media file " . str_replace(";"," and ",str_replace("file://", "", $myflist));
    }
    if (strpos($_GET['to'], "@") === false || strlen($cont) == 0) {
    echo "<!doctype html><html><head><scr" . "ipt type='text/javascript'> function aemail(ame) { window.top.location = ame.href; } </scr" . "ipt></head><body onload='document.getElementById(\"aemail\").click();'><a id='aemail' onclick=' if (navigator.userAgent.match(/Android/i)) { aemail(this); } ' href='mailto:" . urldecode($_GET['to']) . "?subject=" . oururlencode($mysubject) . "&body=" .  oururlencode($mybody) . "' title='Email' style='display:none;'></a></body></html>";
    } else {
    if ($mybody == "Emoji Slideshow is as attached below.") $myflist = " ";
    //if ($mybody == "Emoji Slideshow is as attached below.") echo "<!doctype html><html><head><scr" . "ipt type='text/javascript'> function aemail(ame) { window.top.location = ame.href; } </scr" . "ipt></head><body onload='document.getElementById(\"aemail\").click();'><a id='aemail' onclick=' if (navigator.userAgent.match(/Android/i)) { aemail(this); } ' href='mailto:" . urldecode($_GET['to']) . "?subject=" . oururlencode($mysubject) . "&body=" .  oururlencode($cont) . "' title='Email' style='display:none;'></a></body></html>";
    ourpremail(urldecode($_GET['to']), $mysubject, $mybody, getheaders($cont, $myflist));
    }

  } else if (isset($_GET['url'])) {
    $f = strpos($_GET['url'], '%');
    if ($f === false) {
    if ((isset($_GET['to']) || strpos($_GET['url'], 'file:') === 0) && strpos($_GET['url'], '.wav') !== false) {
    $cont=file_get_contents(str_replace("https:","http:",$_GET['url']));
    if (isset($_GET['to']) && isset($_GET['urlbig']) && isset($_GET['subject'])) {
    $mybody=urldecode($_GET['urlbig']);
    $mysubject=urldecode($_GET['subject']);
    $myflist=$_GET['url'];
    $myfiles=explode(";", $mybody);
    if (sizeof($myfiles) > 1) {
      for ($ii=1; $ii<sizeof($myfiles); $ii++) {
        $myone=explode("&", $myfiles[$ii]);
        if (strpos($myflist, $myone[0]) === false) {
          $myflist.=";" .  $myone[0];
          if ($cont == "") $cont=@file_get_contents($myone[0]);
        }
      }
    }
    if (isset($_GET['body'])) {
      $mysubject.=" " . urldecode($_GET['body']);
    } else {
      $mysubject.=" Please attach media file " . str_replace(";"," and ",str_replace("file://", "", $myflist));
    }
    if (strpos($_GET['to'], "@") === false) {
    echo "<!doctype html><html><head><scr" . "ipt type='text/javascript'> function aemail(ame) { window.top.location = ame.href; } </scr" . "ipt></head><body onload='document.getElementById(\"aemail\").click();'><a id='aemail' onclick=' if (navigator.userAgent.match(/Android/i)) { aemail(this); } ' href='mailto:" . urldecode($_GET['to']) . "?subject=" . oururlencode($mysubject) . "&body=" .  oururlencode($mybody) . "' title='Email' style='display:none;'></a></body></html>";
    } else {
    ourpremail(urldecode($_GET['to']), $mysubject, $mybody, getheaders($cont, $myflist));
    }
    } else {
    header('Cache-Control: max-age=604800');
    header('Content-type: audio/x-wav');
    header('Content-Transfer-Encoding: binary');
    header('Content-Length: ' . filesize($_GET['url']));    
    echo $cont;
    }
    } else {
    echo file_get_contents(str_replace("https:","http:",$_GET['url']));
    }
    } else if ($f < 7) {
    if ((isset($_GET['to']) || strpos($_GET['url'], 'file:') === 0) && strpos(urldecode($_GET['url']), '.wav') !== false) {
    $cont=file_get_contents(str_replace("https:","http:",urldecode($_GET['url'])));
    if (isset($_GET['to']) && isset($_GET['urlbig']) && isset($_GET['subject'])) {
    $mybody=urldecode($_GET['urlbig']);
    $mysubject=urldecode($_GET['subject']);
    $myflist=urldecode($_GET['url']);
    $myfiles=explode(";", $mybody);
    if (sizeof($myfiles) > 1) {
      for ($ii=1; $ii<sizeof($myfiles); $ii++) {
        $myone=explode("&", $myfiles[$ii]);
        if (strpos($myflist, $myone[0]) === false) {
          $myflist.=";" .  $myone[0];
          if ($cont == "") $cont=@file_get_contents($myone[0]);
        }
      }
    }
    if (isset($_GET['body'])) {
      $mysubject.=" " . urldecode($_GET['body']);
    } else {
      $mysubject.=" Please attach Audio File " . str_replace(";"," and ",str_replace("file://", "", $myflist));
    }
    if (strpos($_GET['to'], "@") === false) {
    echo "<!doctype html><html><head><scr" . "ipt type='text/javascript'> function aemail(ame) { window.top.location = ame.href; } </scr" . "ipt></head><body onload='document.getElementById(\"aemail\").click();'><a id='aemail' onclick=' if (navigator.userAgent.match(/Android/i)) { aemail(this); } ' href='mailto:" . urldecode($_GET['to']) . "?subject=" . oururlencode($mysubject) . "&body=" .  oururlencode($mybody) . "' title='Email' style='display:none;'></a></body></html>";
    } else {
    ourpremail(urldecode($_GET['to']), $mysubject, $mybody, getheaders($cont, $myflist));
    }
    } else {
    header('Cache-Control: max-age=604800');
    header('Content-type: audio/x-wav');
    header('Content-Transfer-Encoding: binary');
    header('Content-Length: ' . filesize(urldecode($_GET['url'])));    
    echo $cont;
    }
    } else {
     echo file_get_contents(urldecode(str_replace("https:","http:",$_GET['url'])));
    }
    } else {
    if ((isset($_GET['to']) || strpos($_GET['url'], 'file:') === 0) && strpos($_GET['url'], '.wav') !== false) {
    $cont=file_get_contents(str_replace("https:","http:",$_GET['url']));
    if (isset($_GET['to']) && isset($_GET['urlbig']) && isset($_GET['subject'])) {
    $mybody=urldecode($_GET['urlbig']);
    $mysubject=urldecode($_GET['subject']);
    $myflist=$_GET['url'];
    $myfiles=explode(";", $mybody);
    if (sizeof($myfiles) > 1) {
      for ($ii=1; $ii<sizeof($myfiles); $ii++) {
        $myone=explode("&", $myfiles[$ii]);
        if (strpos($myflist, $myone[0]) === false) {
          $myflist.=";" .  $myone[0];
          if ($cont == "") $cont=@file_get_contents($myone[0]);
        }
      }
    }
    if (isset($_GET['body'])) {
      $mysubject.=" " . urldecode($_GET['body']);
    } else {
      $mysubject.=" Please attach Audio File " . str_replace(";"," and ",str_replace("file://", "", $myflist));
    }
    if (strpos($_GET['to'], "@") === false) {
    echo "<!doctype html><html><head><scr" . "ipt type='text/javascript'> function aemail(ame) { window.top.location = ame.href; } </scr" . "ipt></head><body onload='document.getElementById(\"aemail\").click();'><a id='aemail' onclick=' if (navigator.userAgent.match(/Android/i)) { aemail(this); } ' href='mailto:" . urldecode($_GET['to']) . "?subject=" . oururlencode($mysubject) . "&body=" .  oururlencode($mybody) . "' title='Email' style='display:none;'></a></body></html>";
    } else {
    ourpremail(urldecode($_GET['to']), $mysubject, $mybody, getheaders($cont, $myflist));
    }
    } else {
    header('Cache-Control: max-age=604800');
    header('Content-type: audio/x-wav');
    header('Content-Transfer-Encoding: binary');
    header('Content-Length: ' . filesize($_GET['url']));    
    echo $cont;
    }
    } else {
    echo file_get_contents(str_replace("https:","http:",$_GET['url']));
    }
    }
  } else {
    echo "";
  }
  
?>
