# # The only 2 `public_function's are: ys_split_file(), and it's counterpart # ys_split_buf(). One takes the filename as input, the other the message buffer # (as it were already read in as a file). The other functions are needed by # ys_split_file() and ys_split_buf() and are not really useful by themselves. # # This function from the mobile-mail package: # http://sourceforge.net/projects/mobile-mail # Used with permission # Copyright Jeremy Brand, 2001-2002 # # Used by the ys_split_addresses() function. function make_rcpt_array($str) { # MM specific # $func = 'make_rcpt_array'; # mm_open_func($func); # mm_debug($str); $arr = array(); $addrs = explode(" ", $str); $valid_addr = "[-=_.+a-zA-Z0-9]+@[-_.a-zA-Z0-9]+\.[a-zA-Z]+"; for($i=0; $i < count($addrs); $i++) { $addr = $addrs[$i]; # extract addrs from junk that may surround it ereg("($valid_addr)", $addr, $regs); if ($regs[0] && ereg("^[^-_.+]", $regs[0])) $arr[] = $regs[0]; unset($regs); } $arr = array_unique($arr); # purge any duplicate addrs # MM specific # mm_close_func($func); return $arr; } # This function from the mobile-mail package: # http://sourceforge.net/projects/mobile-mail # Used with permission # Copyright Jeremy Brand, 2001-2002 # # Used by the ys_split_addresses() function. function purge_headers($regex, $headers) { # MM specific # $func = 'purge_headers'; # mm_open_func($func); $arr = array(); $max = count($headers); $plines = ""; for($i=0; $i < $max; $i++) { if (eregi($regex, $headers[$i])) { $plines .= $headers[$i]; # skip over any "folded" content as well while (($i+1) < $max && ereg("^[ \t]", $headers[$i+1])) { $i++; $plines .= $headers[$i]; } continue; } $arr[] = $headers[$i]; } # MM specific # $msg = "purged the following headers:\n>>>\n$plines<<<\n"; # mm_debug($msg); # # mm_close_func($func); return $arr; } # This function from the mobile-mail package: # http://sourceforge.net/projects/mobile-mail # Used with permission # Copyright Jeremy Brand, 2001-2002 # # Used by the has_header() function. # extract the headers that match $names from $headers function extract_header_content($names, $headers) { # MM specific # $func = 'extract_header_content'; # mm_open_func($func); $lines = ""; $max = count($headers); for($i=0; $i < count($names); $i++) { for($j=0; $j < $max; $j++) { $hlen = strlen($names[$i]); if (strncasecmp($headers[$j], $names[$i], $hlen) == 0) { $lines .= substr($headers[$j], $hlen); /* enter into another loop and look for content in "folded" headers. see RFC 2822, section 2.2.3 for more info */ while (($j+1) < $max && ereg("^[ \t]", $headers[$j+1])) $lines .= $headers[++$j]; } } } # MM specific # $msg = "extracted the following addresses:\n>>>\n$lines<<<\n"; # mm_debug($msg); # mm_close_func($func); return $lines; } # This function from the mobile-mail package: # http://sourceforge.net/projects/mobile-mail # Used with permission # Copyright Jeremy Brand, 2001-2002 # # Used by the ys_split_addresses() function. function has_header($needle, $haystack) { $len = strlen($needle); for($i=0; $i < count($haystack); $i++) { if (strncasecmp($haystack[$i], $needle, $len) == 0) return 1; } return 0; } # This function from the mobile-mail package: # http://sourceforge.net/projects/mobile-mail # Used with permission # Copyright Jeremy Brand, 2001-2002 # # Used by the ys_split_file() function. function ys_split_addresses($ys_array) { # MM specific # $func = 'ys_split_addresses'; # mm_open_func($func); $bounce = 0; $headers = $ys_array['headers']; # look for resend-* headers (indication of a 'bounce') $to_s = array("resent-to:", "resent-cc:", "resent-bcc:"); for($i=0; $i < count($to_s); $i++) { if (has_header($to_s[$i], $headers)) $bounce = 1; } # get header contents if (!$bounce) # if no bounce, use standard headers $to_s = array("to:", "cc:", "bcc:"); # get all the content from these headers $rcpts = extract_header_content($to_s, $headers); # separate individual email addresses into an array $rcpts = make_rcpt_array($rcpts); if (!$rcpts) { # MM specific # nir_perror('ys_split_addresses', "No addresses in headers - " . # implode(" ", $to_s), 1); exit; } # MM specific # mm_debug('$rcpts array:'); # mm_debug(mm_var_dump($rcpts)); $ys_array['RCPT_TO'] = $rcpts; # purge email array of any 'bcc's $headers = purge_headers('^(resent-)?bcc: *', $headers); $ys_array['headers'] = $headers; # MM specific # mm_debug(mm_var_dump($ys_array)); # mm_close_func($func); return $ys_array; } # This function from the mobile-mail package: # http://sourceforge.net/projects/mobile-mail # Used with permission # Copyright Jeremy Brand, 2001-2002 # # takes a single email message and returns an array # with the headers elements, body elements, and recipients # # FORMAT OF RETURNED ARRAY # $ys_array['headers'] = array(); # $ys_array['RCPT_TO'] = array(); # $ys_array['body'] = ''; # function ys_split_file($entry) { # MM specific # $func = 'ys_split_file'; # mm_open_func($func); # # $msg = "opening " . OUTBOUND_SPOOL_PATH . $entry . "\n"; # mm_debug($msg); $file_array = file($entry); $count = count($file_array); if ($count <= 0) { # MM specific # nir_perror('ys_split_file', 'could not open ' . OUTBOUND_SPOOL_PATH . # $entry . '.', 1); exit; } /* FORMAT OF ARRAY $ys_array['headers'] = array(); $ys_array['RCPT_TO'] = array(); $ys_array['body'] = ''; */ # $ys_array['headers'][] = 'Received: (Initial drop from localhost [127.0.0.1] by ' .MM_VERSION_STRING. '. www.nirvani.net/software/); ' . gmdate('d M Y H:i:s -0000') . "\r\n"; $headers = TRUE; while($val = array_shift($file_array)) { $line_test = trim($val); if ($headers && $line_test != '') { $ys_array['headers'][] = $val; } else { $headers = FALSE; # Out of headers now /* according to RFC 821 (SMTP) section 4.5.1 (Transparency) if a line begins w/ a '.', you must add another one to the beginning */ # MM specific (we are not using this for outbound SMTP). # if ($val[0] == '.') # $val = '.' . $val; $ys_array['body'] .= $val; } } # $msg = 'Before ys_split_addresses'; # mm_debug($msg); # mm_debug(mm_var_dump($ys_array)); $ys_array = ys_split_addresses($ys_array); # $msg = 'After ys_split_addresses'; # mm_debug($msg); # mm_debug(mm_var_dump($ys_array)); # mm_close_func($func); return $ys_array; } # This function from the mobile-mail package: # http://sourceforge.net/projects/mobile-mail # Used with permission # Copyright Jeremy Brand, 2001-2002 # # takes a single email message and returns an array # with the headers elements, body elements, and recipients # # FORMAT OF RETURNED ARRAY # $ys_array['headers'] = array(); # $ys_array['RCPT_TO'] = array(); # $ys_array['body'] = ''; # function ys_split_buf($in_buf) { # MM specific # $func = 'ys_split_file'; # mm_open_func($func); # # $msg = "opening " . OUTBOUND_SPOOL_PATH . $entry . "\n"; # mm_debug($msg); $tmp_file_array = split("\n", $in_buf); while(list($key, $val) = each($tmp_file_array)) { $file_array[$key] = $val."\n"; } # $file_array = file($entry); $count = count($file_array); if ($count <= 0) { # MM specific # nir_perror('ys_split_file', 'could not open ' . OUTBOUND_SPOOL_PATH . # $entry . '.', 1); exit; } /* FORMAT OF ARRAY $ys_array['headers'] = array(); $ys_array['RCPT_TO'] = array(); $ys_array['body'] = ''; */ # $ys_array['headers'][] = 'Received: (Initial drop from localhost [127.0.0.1] by ' .MM_VERSION_STRING. '. www.nirvani.net/software/); ' . gmdate('d M Y H:i:s -0000') . "\r\n"; $headers = TRUE; while($val = array_shift($file_array)) { $line_test = trim($val); if ($headers && $line_test != '') { $ys_array['headers'][] = $val; } else { $headers = FALSE; # Out of headers now /* according to RFC 821 (SMTP) section 4.5.1 (Transparency) if a line begins w/ a '.', you must add another one to the beginning */ # MM specific (we are not using this for outbound SMTP). # if ($val[0] == '.') # $val = '.' . $val; $ys_array['body'] .= $val; } } # $msg = 'Before ys_split_addresses'; # mm_debug($msg); # mm_debug(mm_var_dump($ys_array)); $ys_array = ys_split_addresses($ys_array); # $msg = 'After ys_split_addresses'; # mm_debug($msg); # mm_debug(mm_var_dump($ys_array)); # mm_close_func($func); return $ys_array; } ?>