* $Id$
*/
-/*
+/*
* rdc822_header class
* input: header_string or array
*/
$priority = 3,
$dnt = '',
$mlist = array(),
- $more_headers = array(); /* only needed for constructing headers
+ $more_headers = array(); /* only needed for constructing headers
in smtp.php */
function parseHeader($hdr) {
if (is_array($hdr)) {
/* Now we can make a new header array with */
/* each element representing a headerline */
- $hdr = explode("\r\n" , $hdr);
+ $hdr = explode("\r\n" , $hdr);
foreach ($hdr as $line) {
$pos = strpos($line, ':');
if ($pos > 0) {
$this->parseContentType('text/plain; charset=us-ascii');
}
}
-
+
function stripComments($value) {
$result = '';
$cnt = strlen($value);
for ($i = 0; $i < $cnt; ++$i) {
- switch ($value{$i}) {
- case '"':
- $result .= '"';
- ++$i;
- while ($value{$i} != '"') {
- if ($value{$i} == '\\s') {
- $result .= '\\';
- ++$i;
- }
- $result .= $value{$i};
- if (++$i > $cnt) { break; }
- }
- $result .= $value{$i};
- break;
- case '(':
- while ($value{$i} != ')') {
- $i += ($value{$i} == '\\' ? 2 : 1);
- }
- break;
- default:
- $result .= $value{$i};
- break;
- }
- }
- return $result;
+ switch ($value{$i}) {
+ case '"':
+ $result .= '"';
+ ++$i;
+ while ($value{$i} != '"') {
+ if ($value{$i} == '\\') {
+ $result .= '\\';
+ ++$i;
+ }
+ $result .= $value{$i};
+ if (++$i > $cnt) { break; }
+ }
+ $result .= $value{$i};
+ break;
+ case '(':
+ while ($value{$i} != ')') {
+ $i += ($value{$i} == '\\' ? 2 : 1);
+ }
+ break;
+ default:
+ $result .= $value{$i};
+ break;
+ }
+ }
+ return $result;
}
-
+
function parseField($field, $value) {
$field = strtolower($field);
switch($field) {
case 'in-reply-to':
$this->in_reply_to = $value;
break;
- case 'message_id':
+ case 'message-id':
$this->message_id = $value;
break;
case 'disposition-notification-to':
$this->dnt = $this->parseAddress($value);
break;
- case 'mime-Version':
+ case 'mime-version':
$value = str_replace(' ', '', $value);
$this->mime = ($value == '1.0' ? true : $this->mime);
break;
break;
case 'content-disposition':
$this->parseDisposition($value);
- break;
+ break;
case 'user-agent':
case 'x-mailer':
$this->xmailer = $value;
$this->mlist('post', $value);
break;
case 'list-reply':
- $this->mlist('reply', $value);
+ $this->mlist('reply', $value);
break;
case 'list-subscribe':
$this->mlist('subscribe', $value);
default:
break;
}
- }
+ }
function parseAddress
($address, $ar=false, $addr_ar = array(), $group = '') {
case '(': /* rip off comments */
$addr_start = $pos;
for (++$pos; $pos < $j && $address{$pos} != ')'; ++$pos) {
- $addr .= $address{$pos};
+ $addr .= $address{$pos};
}
$address_start = substr($address, 0, $addr_start);
$address_end = substr($address, $pos + 1);
- $address = $address_start . $address_end;
+ $address = $address_start . $address_end;
$j = strlen($address);
$pos = $addr_start + 1;
break;
$addr_ar = $result[0];
$pos = $result[1];
$address = substr($address, $pos++);
- $j = strlen($address);
+ $j = strlen($address);
$group = '';
break;
case ';':
if ($group && $addr == '') { /* no addresses found in group */
$name = "$group: Undisclosed recipients;";
$addr_structure->personal = $name;
- $addr_ar[] = $addr_structure;
- return (array($addr_ar, $pos+1));
+ $addr_ar[] = $addr_structure;
+ return (array($addr_ar, $pos+1));
} else {
$addr_structure->personal = $name;
if ($name || $addr) {
$addr_ar[] = $addr_structure;
- }
+ }
}
if ($ar) {
return ($addr_ar);
}
-
return ($addr_ar[0]);
}
-
+
function parseContentType($value) {
$pos = strpos($value, ';');
$props = '';
}
$this->content_type = $content_type;
}
-
+
function parseProperties($value) {
$propArray = explode(';', $value);
$propResultArray = array();
}
return $propResultArray;
}
-
+
function parseDisposition($value) {
$pos = strpos($value, ';');
$props = '';
$disp->properties = $props_a;
$this->disposition = $disp;
}
-
+
function mlist($field, $value) {
$res_a = array();
$value_a = explode(',', $value);
$this->mlist[$field] = $res_a;
}
- /*
+ /*
* function to get the addres strings out of the header.
* Arguments: string or array of strings !
* example1: header->getAddr_s('to').
return $s;
}
-
+
function getAddr_a($arg, $excl_arr = array(), $arr = array()) {
if (is_array($arg)) {
foreach($arg as $argument) {
if (is_object($addr)) {
$email = $addr->mailbox;
$email .= (isset($addr->host) ? '@' . $addr->host : '');
- $email = strtolower($email);
+ $email = strtolower($email);
if ($email && !isset($arr[$email]) && !isset($excl_arr[$email])) {
$arr[$email] = $addr->personal;
}
}
}
}
- return ($arr);
+ return $arr;
}
-
+
function getContentType($type0, $type1) {
$type0 = $this->content_type->type0;
$type1 = $this->content_type->type1;
- return ($this->content_type->properties);
+ return $this->content_type->properties;
}
}
/** msg_header contains all variables available in a bodystructure **/
/** entity like described in rfc2060 **/
- var $type0 = '',
- $type1 = '',
+ var $type0 = '',
+ $type1 = '',
$parameters = array(),
- $id = 0,
- $description = '',
- $encoding='',
+ $id = 0,
+ $description = '',
+ $encoding='',
$size = 0,
- $md5='',
- $disposition = '',
+ $md5='',
+ $disposition = '',
$language='';
-
- /*
+
+ /*
* returns addres_list of supplied argument
* arguments: array('to', 'from', ...) or just a string like 'to'.
* result: string: address1, addres2, ....
- */
-
+ */
+
function setVar($var, $value) {
$this->{$var} = $value;
}
-
+
function getParameter($p) {
$value = strtolower($p);
return (isset($this->parameters[$p]) ? $this->parameters[$p] : '');
}
-
+
function setParameter($parameter, $value) {
$this->parameters[strtolower($parameter)] = $value;
}
$result = ($full ? $addr : $best_dpl);
}
- return ($result);
+ return $result;
}
}
more objects of type message. See documentation in mime.txt for
a better description of how this works.
**/
- var $rfc822_header = '',
+ var $rfc822_header = '',
$mime_header = '',
$flags = '',
$type0='',
- $type1='',
- $entities = array(),
- $parent_ent, $entity,
+ $type1='',
+ $entities = array(),
+ $parent_ent, $entity,
$parent = '', $decoded_body='',
$is_seen = 0, $is_answered = 0, $is_deleted = 0, $is_flagged = 0,
$is_mdnsent = 0,
function setEnt($ent) {
$this->entity_id= $ent;
}
-
+
function addEntity ($msg) {
$msg->parent = &$this;
$this->entities[] = $msg;
$cur_ent_a = explode('.', $this->entity_id);
}
$ent_a = explode('.', $ent);
-
+
$cnt = count($ent_a);
for ($i = 0; $i < $cnt -1; ++$i) {
function setBody($s) {
$this->body_part = $s;
}
-
+
function clean_up() {
$msg = $this;
$msg->body_part = '';
$msg->entities[$i]->clean_up();
}
}
-
+
function getMailbox() {
$msg = $this;
while (is_object($msg->parent)) {
}
return $msg->mailbox;
}
-
+
function calcEntity($msg) {
if (($this->type0 == 'message') && ($this->type1 == 'rfc822')) {
$msg->entity_id = $this->entity_id .'.0'; /* header of message/rfc822 */
$msg->entity_id = $ent;
} else {
$msg->entity_id = $ent_no;
- }
+ }
} else {
$ent = $this->entity_id . ".$ent_no";
$msg->entity_id = $ent;
return $msg->entity_id;
}
-
-
- /*
- * Bodystructure parser, a recursive function for generating the
+
+
+ /*
+ * Bodystructure parser, a recursive function for generating the
* entity-tree with all the mime-parts.
- *
+ *
* It follows RFC2060 and stores all the described fields in the
- * message object.
+ * message object.
*
* Question/Bugs:
- *
+ *
* Ask for me (Marc Groot Koerkamp, stekkel@users.sourceforge.net.
*
*/
$cnt = strlen($read);
for (; $i < $cnt; ++$i) {
- $char = strtoupper($read{$i});
+ $char = strtoupper($read{$i});
switch ($char) {
case '(':
if ($arg_no == 0) {
$arg_a[] = ''; /* not yet desribed in rfc2060 */
}
++$arg_no;
- break;
+ break;
default:
/* unknown argument, skip this part */
$i = $msg->parseParenthesis($read, $i);
}
$arg_a[] = $arg_s;
break;
- case 'n':
+ case 'n':
case 'N':
/* probably NIL argument */
- if (strtoupper(substr($read, $i, 4)) == 'NIL ') {
+ if (strtoupper(substr($read, $i, 4)) == 'NIL ') {
$arg_a[] = '';
++$arg_no;
$i += 2;
if (!$multipart) {
$shifted_args = (($arg_a[0] == 'text') || (($arg_a[0] == 'message') && ($arg_a[1] == 'rfc822')));
$hdr->type0 = $arg_a[0];
- $hdr->type1 = $arg_a[1];
+ $hdr->type1 = $arg_a[1];
$msg->type0 = $arg_a[0];
$msg->type1 = $arg_a[1];
$hdr->description = $arg_a[4];
$hdr->encoding = strtolower($arg_a[5]);
$hdr->entity_id = $msg->entity_id;
- $hdr->size = $arg_a[6];
+ $hdr->size = $arg_a[6];
if ($shifted_args) {
$hdr->lines = $arg_a[7];
$s = 1;
} /* for */
} /* parsestructure */
-
+
function parseProperties($read, $i) {
$properties = array();
$prop_name = '';
return (array($properties, $i));
}
-
+
function parseEnvelope($read, $i, $hdr) {
$arg_no = 0;
$arg_a = array();
$i = $res[1];
++$arg_no;
break;
- case 'N':
+ case 'N':
/* probably NIL argument */
if (strtoupper(substr($read, $i, 3)) == 'NIL') {
$arg_a[] = '';
++$arg_no;
$i += 2;
- }
+ }
break;
case '(':
/* Address structure (with group support)
}
return (array($hdr, $i));
}
-
+
function parseLiteral($read, $i) {
$lit_cnt = '';
for (++$i; $read{$i} != '}'; ++$i) {
}
return (array($s, $i));
}
-
+
function parseQuote($read, $i) {
$s = '';
for (++$i; $read{$i} != '"'; ++$i) {
if ($read{$i} == '\\') {
++$i;
- }
+ }
$s .= $read{$i};
}
- return (array($s, $i));
+ return (array($s, $i));
}
-
+
function parseAddress($read, $i) {
$arg_a = array();
$char = strtoupper($read{$i});
switch ($char) {
case '"':
- case '{':
+ case '{':
$res = ($char == '"' ? $this->parseQuote($read, $i) : $this->parseLiteral($read, $i));
$arg_a[] = $res[0];
$i = $res[1];
break;
case 'n':
- case 'N':
+ case 'N':
if (strtoupper(substr($read, $i, 3)) == 'NIL') {
$arg_a[] = '';
$i += 2;
}
return (array($adr, $i));
}
-
+
function parseDisposition($read, $i) {
$arg_a = array();
for (; $read{$i} != ')'; ++$i) {
switch ($read{$i}) {
case '"':
- case '{':
+ case '{':
case '(':
switch ($read{$i}) {
case '"': $res = $this->parseQuote($read, $i); break;
return (is_object($disp) ? array($disp, $i) : array('', $i));
}
-
+
function parseLanguage($read, $i) {
/* no idea how to process this one without examples */
$arg_a = array();
for (; $read{$i} != ')'; ++$i) {
switch ($read{$i}) {
case '"':
- case '{':
+ case '{':
case '(':
switch ($read{$i}) {
case '"': $res = $this->parseQuote($read, $i); break;
return (is_object($lang) ? array($lang, $i) : array('', $i));
}
-
+
function parseParenthesis($read, $i) {
for (; $read{$i} != ')'; ++$i) {
switch ($read{$i}) {
case '"':
- case '{':
+ case '{':
case '(':
switch ($read{$i}) {
case '"': $res = $this->parseQuote($read, $i); break;
break;
default: break;
}
- }
+ }
return $i;
}
for ($i = 1; $i < $count; ++$i) {
$line = trim($body[$i]);
- if (($mime_header || $rfc822_header) &&
+ if (($mime_header || $rfc822_header) &&
(preg_match("/^.*boundary=\"?(.+(?=\")|.+).*/i", $line, $reg))) {
$bnd = $reg[1];
- $bndreg = $bnd;
- $bndreg = str_replace("\\", "\\\\", $bndreg);
+ $bndreg = $bnd;
+ $bndreg = str_replace("\\", "\\\\", $bndreg);
$bndreg = str_replace("?", "\\?", $bndreg);
- $bndreg = str_replace("+", "\\+", $bndreg);
- $bndreg = str_replace(".", "\\.", $bndreg);
+ $bndreg = str_replace("+", "\\+", $bndreg);
+ $bndreg = str_replace(".", "\\.", $bndreg);
$bndreg = str_replace("/", "\\/", $bndreg);
$bndreg = str_replace("-", "\\-", $bndreg);
$bndreg = str_replace("(", "\\(", $bndreg);
if ($msg->type0 == 'multipart') {
$mime_header = true;
}
- }
-
+ }
+
if ((($line{0} == '-') || $rfc822_header) && isset($boundaries[0])) {
$cnt=count($boundaries)-1;
$bnd = $boundaries[$cnt]['bnd'];
$bndreg = $boundaries[$cnt]['bndreg'];
-
+
$regstr = '/^--'."($bndreg)".".*".'/';
if (preg_match($regstr, $line, $reg)) {
$bndlen = strlen($reg[1]);
- $bndend = false;
+ $bndend = false;
if (strlen($line) > ($bndlen + 3)) {
if (($line{$bndlen+2} == '-') && ($line{$bndlen+3} == '-')) {
$bndend = true;
} else {
if ($header) { }
}
- }
+ }
}
}
return $entity;
}
-
+
function findRelatedEntity() {
- $msgs = array();
+ $msgs = array();
$entcount = count($this->entities);
for ($i = 0; $i < $entcount; ++$i) {
return $msgs;
}
-
+
function getAttachments($exclude_id=array(), $result = array()) {
if (($this->type0 == 'message') && ($this->type1 == 'rfc822')) {
$this = $this->entities[0];
}
if (!$exclude) {
- if (($entity->type0 == 'multipart') &&
+ if (($entity->type0 == 'multipart') &&
($entity->type1 != 'related')) {
$result = $entity->getAttachments($exclude_id, $result);
} else if ($entity->type0 != 'multipart') {
}
return $result;
- }
+ }
}
class smime_message {
}
class content_type {
- var $type0 = 'text',
- $type1 = 'plain',
+ var $type0 = 'text',
+ $type1 = 'plain',
$properties = '';
function content_type($type) {