Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require_once './swift/lib/swift_required.php';// IMAP-Settings:
- $hostname = "{imap.example.com:993/imap/ssl}INBOX";
- $username = "username";
- $password = "password"; // Script-Settings:
- $targetMail="private@example.com"; // "hidden" target mail-address
- $thisMail="webmaster@example.com"; // "official" mail-address (which receives the spam)
- $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>";
- $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!";
- $templateForward="new message redirected";
- $allowedSenders=explode(",",$whitelist);
- $inbox = imap_open($hostname,$username,$password) or die("Sorry, connection failed");
- $emails = imap_search($inbox,"UNSEEN");
- $count=0;
- echo "<pre>";
- if($emails) {
- $transport = Swift_MailTransport::newInstance();
- foreach($emails as $email) {
- $count++;
- $header = imap_fetch_overview($inbox,$email,0);
- $subject=$header[0]->subject;
- $sender=$header[0]->from;
- $messageHeader = imap_fetchheader($inbox, 1)
- if (strpos($messageHeader,"X-RESPONDERDATE")!==false) {
- continue; // no wild bouncing, please
- }
- if (strpos($sender,$targetMail!==false || strpos($sender,$thisMail!==false) {
- // We want no loops... :)
- continue;
- }
- echo "retrieving ".$subject." from ".$sender."\r\n";
- $mailer = Swift_Mailer::newInstance($transport);
- $message = Swift_Message::newInstance();
- $swiftheaders = $message->getHeaders();
- $swiftheaders->addTextHeader('X-RESPONDERDATE', date('Y-m-d H:i:s'));
- $message
- ->setSubject("Re:".$subject)
- ->setFrom($thisMail)
- ->setTo($sender)
- ->setBody($html, 'text/html')
- ->addPart($plain, 'text/plain')
- ;
- $result = $mailer->send($message);
- echo "answered\r\n";
- imap_setflag_full($inbox, imap_uid($inbox,$email), "\\Seen \\Flagged", ST_UID);
- }
- }
- imap_close($inbox);
- echo "done redirecting ".$count." mails\r\n";
- echo "</pre>";
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement