Created
March 30, 2010 18:50
-
-
Save navarr/349437 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Email | |
{ | |
public $email = array("raw" => array(),"clean" => array(),"head" => array(),"body" => array()); | |
public $headers; | |
function load($raw_email) | |
{ | |
$this->email["raw"] = $raw_email; | |
list($head,$body) = $this->split(); | |
$this->email["head"] = $head; | |
$this->email["body"] = $body; | |
$this->loadHeaders(); | |
} | |
function split($raw_email = null) | |
{ | |
if($raw_email == null) { $raw_email = $this->email["raw"]; } | |
$lines = explode("\n",$raw_email); | |
$splittingheaders = true; | |
$headers = ""; | |
$message = ""; | |
for($i = 0;$i < count($lines); $i++) | |
{ | |
if($splittingheaders) | |
{ | |
$headers .= $lines[$i]."\n"; | |
} | |
else | |
{ | |
$message .= $lines[$i]."\n"; | |
} | |
if(trim($lines[$i]) == "") | |
{ | |
$splittingheaders = false; | |
} | |
} | |
return array($headers,$message); | |
} | |
function loadHeaders($head = null) | |
{ | |
$this->headers = array(); | |
if($head == null) { $head = $this->email["head"]; } | |
$head = str_replace(str_repeat(" ",8),"\t",$head); | |
$head = explode("\n",$head); | |
foreach($head as $header) | |
{ | |
if(substr($header,0,1) != "\t" && trim($header) != "") | |
{ | |
list($var,$val) = explode(": ",$header,2); | |
if(isset($this->headers[$var]) && !is_array($this->headers[$var])) | |
{ | |
$oval = $this->headers[$var]; | |
$this->headers[$var] = array(); | |
$this->headers[$var][] = $oval; | |
$this->headers[$var][] = $val; | |
} | |
else if (isset($this->headers[$var])) | |
{ | |
$this->headers[$var][] = $val; | |
} | |
else | |
{ | |
$this->headers[$var] = $val; | |
} | |
} | |
} | |
} | |
function cleanHeaders() | |
{ | |
if(isset($this->headers["Received"])) | |
{ unset($this->headers["Received"]); } | |
if(isset($this->headers["Return-Path"])) | |
{ unset($this->headers["Return-Path"]); } | |
if(isset($this->headers["Received-SPF"])) | |
{ unset($this->headers["Received-SPF"]); } | |
if(isset($this->headers["Authentication-Results"])) | |
{ unset($this->headers["Authentication-Results"]); } | |
if(isset($this->headers["Delivered-To"])) | |
{ unset($this->headers["Delivered-To"]); } | |
if(isset($this->headers["Message-ID"])) | |
{ unset($this->headers["Message-ID"]); } | |
} | |
function send($email) | |
{ | |
unset($this->headers["To"]); | |
$subj = $this->headers["Subject"]; | |
unset($this->headers["Subject"]); | |
$headers = array(); | |
foreach($this->headers as $var => $val) | |
{ | |
$headers[] = "{$var}: $val"; | |
} | |
$this->headers["To"] = $email; | |
$this->headers["Subject"] = $subj; | |
return mail($email,$subj,$this->email["body"],implode("\n",$headers)); | |
} | |
} | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/local/php5/bin/php | |
<?php | |
// Domains | |
$domains = array(); | |
$domains[] = "mms.att.net"; // AT&T | |
$domains[] = "mms.mycricket.com"; // Cricket | |
$domains[] = "vmpix.com"; // Virgin Mobile USA | |
$domains[] = "mms.alltel.net"; // Alltel | |
$domains[] = "vzwpix.com"; // Verizon | |
$domains[] = "myboostmobile.com"; // Boost Mobile | |
$domains[] = "messaging.sprintpcs.com"; // Sprint | |
$domains[] = "tmomail.net"; // T-Mobile | |
$domains[] = "mymetropcs.com"; // Metro PCS | |
// Get Email | |
$fd = fopen("php://stdin","r"); | |
$raw = ""; | |
while(!feof($fd)) | |
{ | |
$raw .= fread($fd,1024); | |
} | |
fclose($fd); | |
// Remove the Stupid DreamHost Addition to the Headers | |
list(,$raw) = explode("\n",$raw,2); // Get rid of fucking Dreamhost Addition... | |
// Setup the MIME Stuffs | |
require_once("mime.php"); | |
$email = new Email; | |
// Load and Clean Email | |
$email->load($raw); | |
$email->cleanHeaders(); | |
// Create the Number it is to | |
$to = $email->headers["X-DH-Original-To"]; | |
if(strpos($to,"<") !== FALSE) | |
{ | |
$to = explode("<",$to,2); | |
list($to,) = explode(">",$to[1],2); | |
} | |
list($to,) = explode("@",$to,2); | |
$to = trim($to); | |
// Send to Carriers | |
if(strlen($to) == 10 && intval($to) == $to) | |
{ | |
foreach($domains as $domain) | |
{ | |
$email->send("{$to}@{$domain}"); | |
} | |
mylog("Sent Email from {$email->headers["From"]} to {$to}"); | |
} | |
// Log Function | |
function mylog($data) | |
{ | |
$time = date("[H:i:s]"); | |
file_put_contents("/home/gvoms_bridge_mms/actions.log","{$time} {$data}\n",FILE_APPEND); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/local/php5/bin/php | |
<?php | |
// Domains | |
$domains = array(); | |
$domains[] = "message.alltel.com"; // Alltel | |
$domains[] = "txt.att.net"; // AT&T/Net10 | |
// $domains[] = "mmode.com"; // Cingular via AT&T | |
// $domains[] = "cingularme.com"; // Cingular | |
$domains[] = "myboostmobile.com"; // Boost Mobile | |
$domains[] = "sms.mycricket.com"; // Cricket | |
$domains[] = "messaging.nextel.com"; // Nextel | |
$domains[] = "messaging.sprintpcs.com"; // Sprint | |
$domains[] = "tmomail.net"; // T-Mobile | |
$domains[] = "vtext.com"; // Verizon | |
$domains[] = "vmobl.com"; // Virgin Mobile USA | |
$domains[] = "vmobile.ca"; // Virgin Mobile Canada | |
$domains[] = "cwemail.com"; // Centennial Wireless | |
$domains[] = "csouth1.com"; // Cellular South | |
$domains[] = "gocbw.com"; // Cincinnati Bell | |
$domains[] = "qwestmp.com"; // Qwest | |
$domains[] = "txt.bellmobility.ca"; // Bell (Canada) | |
$domains[] = "msg.telus.com"; // Telus | |
$domains[] = "pcs.rogers.com"; // Rogers | |
$domains[] = "mymetropcs.com"; // Metro PCS | |
$domains[] = "pcs.ntelos.net"; // Ntelos | |
// Get Email | |
$fd = fopen("php://stdin","r"); | |
$raw = ""; | |
while(!feof($fd)) | |
{ | |
$raw .= fread($fd,1024); | |
} | |
fclose($fd); | |
// Remove the Stupid Dreamhost Addition to the Headers | |
list(,$raw) = explode("\n",$raw,2); | |
// Setup the MIME Stuffs | |
require_once("mime.php"); | |
$email = new Email; | |
// Load and Clean Email | |
$email->load($raw); | |
$email->cleanHeaders(); | |
// Create the Number it is to | |
$to = $email->headers["X-DH-Original-To"]; | |
if(strpos($to,"<") !== FALSE) | |
{ | |
$to = explode("<",$to,2); | |
list($to,) = explode(">",$to[1],2); | |
} | |
list($to,) = explode("@",$to,2); | |
$to = trim($to); | |
// Send to Carriers | |
if(strlen($to) == 10 && intval($to) == $to) | |
{ | |
foreach($domains as $domain) | |
{ | |
// $email->headers["To"] = "{$to}@{$domain}"; | |
$email->send("{$to}@{$domain}"); | |
} | |
mylog("Sent Email from {$email->headers["From"]} to {$to}"); | |
} | |
// Log Function | |
function mylog($data) | |
{ | |
$time = date("[H:i:s]"); | |
file_put_contents("/home/gvoms_bridge_sms/actions.log","{$time} {$data}\n",FILE_APPEND); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment