Skip to content
Snippets Groups Projects
Commit 97d3ccef authored by Jared Hancock's avatar Jared Hancock
Browse files

emails: Allow specifying how deep to recurse

Previously, the mail parsing and fetching system would recurse unbounded
searching for bodies by content-type
parent cc584e58
No related branches found
No related tags found
No related merge requests found
......@@ -311,7 +311,7 @@ class MailFetcher {
}
//search for specific mime type parts....encoding is the desired encoding.
function getPart($mid, $mimeType, $encoding=false, $struct=null, $partNumber=false) {
function getPart($mid, $mimeType, $encoding=false, $struct=null, $partNumber=false, $recurse=-1) {
if(!$struct && $mid)
$struct=@imap_fetchstructure($this->mbox, $mid);
......@@ -345,11 +345,12 @@ class MailFetcher {
//Do recursive search
$text='';
if($struct && $struct->parts) {
if($struct && $struct->parts && $recurse) {
while(list($i, $substruct) = each($struct->parts)) {
if($partNumber)
$prefix = $partNumber . '.';
if(($result=$this->getPart($mid, $mimeType, $encoding, $substruct, $prefix.($i+1))))
if (($result=$this->getPart($mid, $mimeType, $encoding,
$substruct, $prefix.($i+1), $recurse-1)))
$text.=$result;
}
}
......
......@@ -197,7 +197,7 @@ class Mail_Parse {
return $body;
}
function getPart($struct, $ctypepart) {
function getPart($struct, $ctypepart, $recurse=-1) {
if($struct && !$struct->parts) {
$ctype = @strtolower($struct->ctype_primary.'/'.$struct->ctype_secondary);
......@@ -213,9 +213,10 @@ class Mail_Parse {
}
$data='';
if($struct && $struct->parts) {
if($struct && $struct->parts && $recurse) {
foreach($struct->parts as $i=>$part) {
if($part && !$part->disposition && ($text=$this->getPart($part,$ctypepart)))
if($part && !$part->disposition
&& ($text=$this->getPart($part,$ctypepart,$recurse - 1)))
$data.=$text;
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment