Source Code For gmail.php

Turn Line Numbers On
<?php
function getmicrotime(){
    list(
$usec$sec) = explode(" ",microtime()); 
    return ((float)
$usec + (float)$sec); 
}

$time_before=getmicrotime();
$refresh=3;
if (!
$_GET['avg_time']) {
    
$avg_time=3;
}else{
    
$avg_time=$_GET['avg_time'];
}

if (
$_GET['stop']=='ok'){
        
$next=$_GET['id']+1;
        
$log=fopen("gmail_log.html","a+");
        
fwrite($log,"<p>Stopped on ".date("d/m/Y @ H:i")." at message number ".$_GET['id']."</p>\n");
        
fwrite($log,"<a href=\"gmail.php?num=".$next."&my_addr=".$_GET['addr']."&restart=1&start=1&max_num=".$_GET['max_num']."&avg_time=$avg_time\">Restart</a></p>\n");
        
fclose($log);
}

if (!
$_GET['num'] && $_GET['start']==1){
        
$time=intval($_GET['max_num']*$refresh+$_GET['max_num']*$avg_time);
        
$jour=intval(date("j",$time))-1;
        
$date=$jour." days ".date("H",$time)." hours ".date("i",$time)." minutes";
        
$log=fopen("gmail_log.html","w+");
        
fwrite($log,"<p>Started on ".date("d/m/Y @ H:i")."<br />$max_num messages to send, which should take about $date.</p>\n");
        
fclose($log);
}
if (
$_GET['restart']==1){
        
$left=$_GET['max_num']-$_GET['num'];
        
$time=intval(($left $refresh) + ($left $avg_time));
        
$jour=intval(date("j",$time))-1;
        
$date=$jour." days ".date("H",$time)." hours ".date("i",$time)." minutes";
        
$log=fopen("gmail_log.html","a+");
        
fwrite($log,"<p>Restarted on ".date("d/m/Y @ H:i")."<br />$left messages left to send, which should take about $date.</p>\n");
        
fclose($log);
}
if (
$_GET['num'] && $_GET['num']==$_GET['max_num']){
        
$log=fopen("gmail_log.html","a+");
        
fwrite($log,"<p>Finished on ".date("d/m/Y @ H:i")."</p>\n");
        
fclose($log);

        echo 
"<p>$j messages sent.<br /><a href='gmail_log.html'>View Log</a></p>";
}

if (
$_POST['action']=="go" && !$_GET['max_num']){
  
$my_addr=$_REQUEST['my_addr'];
  if (
eregi("@gmail.com",$my_addr)){
     
$nom_fichier $_FILES['fichier']['tmp_name'];
      
$nom_destination 'mailbox';
      
move_uploaded_file($nom_fichier$nom_destination);
      
//echo $_FILES['fichier']['error'];
      
$mail=fopen("mailbox","r");
      
$max_num=0;
      while (!
feof($mail)) {
        
$line.=fread($mail,4096);

      }
    
fclose($mail);
    
$emails=explode("\nFrom - ",$line);
    
$i=0;
    if (!
is_dir("tmp_mail")) mkdir("tmp_mail",0755);
    foreach(
$emails as $email) {
        
$max_num++;
        if (
$i!=0$email="\nFrom - ".$email;
        
$message_file=fopen("tmp_mail/message$i.txt","w+");
        
fwrite($message_file,$email);
        
fclose($message_file);
        
$mess=fopen("tmp_mail/message$i.txt","r");
        
$headers='';
        
$text='';
        
$in_header="yes";
        
$line_num=0;
        while (!
feof($mess)) {
          
$line=fgets($mess);
          if (!
eregi("[a-z0-9_-]",$line) && $line_num>0){
            
$in_header="no";
          }
          if (
$in_header=="yes"){
             
$headers.=eregi_replace("^[ \n\t\r].*","",$line);
          }else{
             
$text.=$line;
          }
        
$line_num++;
        }

        
fclose($mess);
        
$headers=trim(eregi_replace("\nTo: ([^\n]*)","",$headers));
        
ereg("\nSubject: ([^\n]*)",$headers,$sub);
        
$subject=trim($sub[1]);
        
$headers=eregi_replace("\nReceived: [^\n]*","",$headers);
        
$headers=eregi_replace("\ncc: [^\n]*","",$headers);
        
$headers=eregi_replace("\nbcc: [^\n]*","",$headers);
        
$headers=eregi_replace("\nSubject: [^\n]*","",$headers);
        
$sending=fopen("tmp_mail/message$i.txt","w");
        
fwrite($sending,$subject."\n{[]}\n".$headers."\n{[]}\n".rtrim($text));
        
//fwrite($sending,$headers);
        
fclose($sending);
        
$to=$my_addr;
        
$i++;
    }
    
?>
    <html>
    <head>
    <?php
    
echo "<meta http-equiv=\"Refresh\" content=\"$refresh;url=http://jfoucher/gmail.php?start=1&max_num=$max_num&my_addr=$to&num=0\">";
    echo 
"</head><body>";
    if(!
unlink("mailbox"))
    {
    echo 
"Could not remove temporary mailbox file";
    }else{
    echo 
"Temporary mailbox file removed";
    }
    
//header("location: http://jfoucher/gmail.php?start=1&max_num=$max_num&my_addr=$to&num=0");
    
echo "</body></html>";
  }else{
  echo 
"Wrong address";
  }

}

if (
$_GET['start']==1){

      
$i=$_GET['num'];
      if(
$mess=fopen("tmp_mail/message$i.txt","r")){
        
$buffer='';
        while (!
feof($mess)){
          
$buffer.=fread($mess,4096);
        }
        
fclose($mess);
        list(
$subject,$headers,$message)=explode("\n{[]}\n",$buffer);
        
$my_headers="User-Agent: GMail Uploader 0.2";
        
ereg("(\nFrom: [^\n]*)",$headers,$head);
        
$my_headers.=$head[1];
        
ereg("(\nMIME-Version: [^\n]*)",$headers,$head);
        
$my_headers.=$head[1];
        
ereg("(\nMailing-List: [^\n]*)",$headers,$head);
        
$my_headers.=$head[1];
        
ereg("(\nPrecedence: [^\n]*)",$headers,$head);
        
$my_headers.=$head[1];
        
ereg("(\nList-Unsubscribe: [^\n]*)",$headers,$head);
        
$my_headers.=$head[1];
        
ereg("(\nDate: [^\n]*)",$headers,$head);
        
$my_headers.=$head[1];
        
ereg("(\nReply-To: [^\n]*)",$headers,$head);
        
$my_headers.=$head[1];
        
ereg("(\nContent-Type: [^\n]*)",$headers,$head);
        
$my_headers.=$head[1];
        
ereg("(\nContent-Transfer-Encoding: [^\n]*)",$headers,$head);
        
$my_headers.=$head[1];
        
ereg("(\nMessage-ID: [^\n]*)",$headers,$head);
        
$my_headers.=$head[1];
        
ereg("(\nReferences: [^\n]*)",$headers,$head);
        
$my_headers.=$head[1];
        
ereg("(\nIn-Reply-To: [^\n]*)",$headers,$head);
        
$my_headers.=$head[1];
        
//echo $my_headers;
        
if (mail($_GET['my_addr'], $subject$message$my_headers)) {
          
unlink("tmp_mail/message$i.txt");
          
$time_spent=getmicrotime()-$time_before;
          
$avg_time=($_GET['avg_time']*$i $time_spent)/($i+1);
          
?>
          <html>
          <head>
          <?php
          $max
=$_GET['max_num']-1
          
if ($i<$max){
            
?>
            <meta http-equiv="Refresh" content="<?php echo $refresh?>;url=http://jfoucher/gmail.php?num=<?php echo ($i+1); ?>&my_addr=<?php echo $my_addr?>&max_num=<?php echo $_GET['max_num']; ?>&avg_time=<?php echo $avg_time?>&start=1">
            <?php
          
}
          
?>
          </head>
          <body>
          <?php
            
echo "<p>Message <strong>$i</strong> sent to: $to Subject: $subject</p>
            <p><a href=\"gmail.php?stop=ok&id=$i&I_Love8Maria=true&addr=$my_addr&max_num="
.$_GET['max_num']."&avg_time=$avg_time\">Stop !</a><br />
            <a href=\"gmail_log.html\" target=\"_blank\">View log</a></p>"
;
          
$left=$_GET['max_num']-$_GET['num'];
          
$time=intval(($left $refresh) + ($left $avg_time));
          
$jour=intval(date("j",$time))-1;
          
$heure=intval(date("H",$time))-1;
          
$date=$jour." days ".$heure." hours ".date("i",$time)." minutes";
          echo  
"<p>".$left." messages and ".$date." to go ($time seconds).</p>";
          
$log=fopen("gmail_log.html","a+");
          
fwrite($log,"<p>Message <strong>$i</strong> sent in $time_spent seconds ($subject)</p>\n");
          
fclose($log);
        }else{
          echo 
"<html><body>";
          
$log=fopen("gmail_log.html","a+");
          
fwrite($log,"<p style='color:#c00;font-size:1.3em;'>Mail <strong>$i</strong> failed</p>\n");
          
fclose($log);
          echo 
"<p style='color:#c00;font-size:1.3em;'>Message <strong>$i</strong> failed ($subject)</p>
          <p><a href=\"gmail.php?stop=ok&id=$i&max_num="
.$_GET['max_num']."&addr=$my_addr&avg_time=$avg_time\">Stop !</a><br />
          <a href=\"gmail_log.html\" target=\"_blank\">View log</a></p>"
;
        }
        
?>
        </body>
        </html>
        <?php
       
}else{
       echo 
"Could not open temporary email file";
       }
}else{
?>

  <html>
  <body>
  <form action="gmail.php" method="post" enctype="multipart/form-data">
  <p>
  <label for="email">Email</label>
  <input type="text" value="@gmail.com" name="my_addr" id="my_addr" />
  </p>
  <p>
  <label for="fichier">mbox file</label>
  <input type="file" name="fichier" id="fichier" />
  </p>
  <input type="submit" name="action" id="action" value="go" />
  </form>
  <p><a href="gmail_log.html">View Log</a></p>
  </body>
  </html>
  <?php
}
?>