Advertisement
Guest User

Untitled

a guest
Jun 12th, 2017
685
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.45 KB | None | 0 0
  1. <?php
  2.    require_once './swift/lib/swift_required.php';// IMAP-Settings:
  3.    $hostname = "{imap.example.com:993/imap/ssl}INBOX";
  4.    $username = "username";
  5.    $password = "password"; // Script-Settings:
  6.    $targetMail="private@example.com"; // "hidden" target mail-address
  7.    $thisMail="webmaster@example.com"; // "official" mail-address (which receives the spam)
  8.  
  9.    $html="<html><body>Thanks for your mail. Please note that this mail is no more. It has ceased to be! It is expired and gone to meet its maker! This is an Ex-Mail!<br/>This mail will not be forwarded. No one will see this until you forward it to my new mail-address. Thanks!</body></html>";
  10.    $plain="Thanks for your mail. Please note that this mail is no more. It has ceased to be! It is expired and gone to meet its maker! This is an Ex-Mail!";
  11.    $templateForward="new message redirected";
  12.  
  13.    $allowedSenders=explode(",",$whitelist);
  14.    $inbox = imap_open($hostname,$username,$password) or die("Sorry, connection failed");
  15.    $emails = imap_search($inbox,"UNSEEN");
  16.    $count=0;
  17.    echo "<pre>";
  18.    if($emails) {
  19.      $transport = Swift_MailTransport::newInstance();
  20.      foreach($emails as $email) {
  21.         $count++;
  22.         $header = imap_fetch_overview($inbox,$email,0);
  23.         $subject=$header[0]->subject;
  24.         $sender=$header[0]->from;
  25.  
  26.         $messageHeader =  imap_fetchheader($inbox, 1)
  27.         if (strpos($messageHeader,"X-RESPONDERDATE")!==false) {
  28.           continue; // no wild bouncing, please
  29.         }
  30.  
  31.         if (strpos($sender,$targetMail!==false || strpos($sender,$thisMail!==false) {
  32.            // We want no loops... :)
  33.            continue;
  34.         }
  35.         echo "retrieving ".$subject." from ".$sender."\r\n";
  36.         $mailer = Swift_Mailer::newInstance($transport);
  37.         $message = Swift_Message::newInstance();
  38.         $swiftheaders = $message->getHeaders();
  39.         $swiftheaders->addTextHeader('X-RESPONDERDATE', date('Y-m-d H:i:s'));
  40.            $message
  41.               ->setSubject("Re:".$subject)
  42.               ->setFrom($thisMail)
  43.               ->setTo($sender)
  44.               ->setBody($html, 'text/html')
  45.               ->addPart($plain, 'text/plain')
  46.            ;
  47.            $result = $mailer->send($message);
  48.            echo "answered\r\n";
  49.        
  50.         imap_setflag_full($inbox, imap_uid($inbox,$email), "\\Seen \\Flagged", ST_UID);
  51.      }
  52.   }
  53.   imap_close($inbox);
  54.   echo "done redirecting ".$count." mails\r\n";
  55.   echo "</pre>";
  56. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement