Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3931164
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T23:19:33+00:00 2026-05-19T23:19:33+00:00

I’m wondering if there is any php class to handle pipe incoming mail and

  • 0

I’m wondering if there is any php class to handle pipe incoming mail and split headers, body, and split the headers into parts too to easily gather subject and stuffs.

Any recommandations?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T23:19:34+00:00Added an answer on May 19, 2026 at 11:19 pm
    class HTMLParserIterator
    {
        var $contents;
        var $pos=0;
        var $endPos=0;
        function HTMLParserIterator( $contents )
        {
            $this->contents=$contents;
            $this->pos=0;
            $this->endPos=strlen($contents);
        }
        function setPos( $pos )
        {
            $this->pos=$pos;
        }
        function getPos()
        {
            return $this->pos;
        }
        function hasMore()
        {
            return $this->pos <$this->endPos;
        }
        function getChar()
        {
            return $this->hasMore()?$this->contents[$this->pos++]:'';
        }
        function peek()
        {
            return $this->hasMore()?$this->contents[$this->pos]:'';
        }
        function skip($num=1 )
        {
            $this->pos=min($this->pos+$num,$this->endPos);
        }
        function getChars($num)
        {
            $out='';
            $len=min($num,$this->endPos-$this->pos);
            $out=substr($this->contents,$this->pos,$len);
            $this->pos+=$len;
            return $out;
        }
        function readUntil( $until,$ignoreCase=true )
        {
            $end=$ignoreCase?stripos ( $this->contents, $until ,$this->pos ):strpos ( $this->contents, $until ,$this->pos );
            if($end===false)
            {
                $end=$this->endPos;
            }
            $out=substr($this->contents,$this->pos,$end-$this->pos);
            $this->pos=$end;
            return $out;
        }
        function skipWhiteSpace()
        {
            $out=0;
            while( $this->hasMore() && isWhiteSpace( $this->contents[$this->pos] ) )
            {
                $out++;
                $this->pos++;
            }
            return $out;
        }
        function match( $str,$ignoreCase=true )
        {
            if( sWith($this->contents,$str,$ignoreCase,$this->pos ) )
            {
                $out=substr($this->contents,$this->pos,strlen($str));
                $this->pos+=strlen($str);
                return true;
            }
            return false;
        }
    }
    define("HTMLParserTag_CONTENT",0);
    define("HTMLParserTag_OPEN",1);
    define("HTMLParserTag_CLOSE",2);
    define("HTMLParserTag_STANDALONE",3);
    define("HTMLParserTag_COMMENT",4);
    define("HTMLParserTag_EXTENDED_COMMENT",5);
    define("HTMLParserTag_SCRIPT",6);
    define("HTMLParserTag_STYLE",7);
    define("HTMLParserTag_TEXTAREA",8);
    
    class HTMLParserSectionTag
    {
    
        var $type;
        var $value;
        var $attrs=Array();
        function HTMLParserSectionTag( &$iterator )
        {
            if( ($value= $iterator->match( '<!--' ))!==false)
            {
                $this->type=HTMLParserTag_EXTENDED_COMMENT;
                $this->value=$iterator->readUntil('-->');
                $iterator->skip(3);
            }
            else if( ($value= $iterator->match( '<!' ))!==false)
            {
                $this->type=HTMLParserTag_COMMENT;
                $this->value=$iterator->readUntil('>');
                $iterator->skip(1);
            }
            else if( ($value= $iterator->match( '</' ))!==false)
            {
                $this->type=HTMLParserTag_CLOSE;
                $ch=$iterator->getChar();
                $buffer='';
                while( $ch!='' && !isWhiteSpace($ch) && $ch!='>' && $ch!='/')
                {
                    $this->value.=$ch;
                    $ch=$iterator->getChar();
                }
                if( $this->value=='' )
                {
                    $this->value='<'.$ch;
                    $this->type=HTMLParserTag_CONTENT;
                }
                else if( $ch=='/' && ($value= $iterator->match( '>' ))!==false )
                {
                }
                else if($ch!='>')
                {
                    $endOfTag=$this->readAttrs($iterator);
                }
            }
            else if( ($value= $iterator->match( '<' ))!==false)
            {
                $this->type=HTMLParserTag_OPEN;
                $ch=$iterator->getChar();
                $buffer='';
                while( $ch!='' && !isWhiteSpace($ch) && $ch!='>' && $ch!='/')
                {
                    $this->value.=$ch;
                    $ch=$iterator->getChar();
                }
                if( $this->value=='' )
                {
                    $this->value='<'.$ch;
                    $this->type=HTMLParserTag_CONTENT;
                }
                else if( $ch=='/' && ($value= $iterator->match( '>' ))!==false )
                {
                    $this->type=HTMLParserTag_STANDALONE;
                }
                else if($ch!='>')
                {
                    $endOfTag=$this->readAttrs($iterator);
                    if($endOfTag=='/>')
                    {
                        $this->type=HTMLParserTag_STANDALONE;
                    }
                }
            }
            else
            {
                $this->value=$iterator->readUntil('<');
                $this->type=HTMLParserTag_CONTENT;
            }
            if( $this->type==HTMLParserTag_OPEN && strtolower($this->value)=="script" )
            {
                $this->readScript($iterator);
            }
            else if( $this->type==HTMLParserTag_STANDALONE && strtolower($this->value)=="script" )
            {
                $this->type=HTMLParserTag_SCRIPT;
                $this->value='';
            }
            else if( $this->type==HTMLParserTag_OPEN && strtolower($this->value)=="textarea" )
            {
                $this->type=HTMLParserTag_TEXTAREA;
                $this->readUntilEndTag($iterator,"textarea");
            }
            else if( $this->type==HTMLParserTag_STANDALONE && strtolower($this->value)=="textarea" )
            {
                $this->type=HTMLParserTag_TEXTAREA;
                $this->value='';
            }
            else if( $this->type==HTMLParserTag_OPEN && strtolower($this->value)=="style" )
            {
                $this->type=HTMLParserTag_STYLE;
                $this->readUntilEndTag($iterator,"style");
            }
            else if( $this->type==HTMLParserTag_STANDALONE && strtolower($this->value)=="style" )
            {
                $this->type=HTMLParserTag_STYLE;
                $this->value='';
            }
        }
        function readScript(&$iterator)
        {
            $this->type=HTMLParserTag_SCRIPT;
            $this->readUntilEndTag($iterator,"script");
        }
        function readUntilEndTag(&$iterator,$tag)
        {
    
            $this->value='';
            while ($iterator->hasMore() )
            {
                $this->value.=$iterator->readUntil( '</'.$tag );
                if( $iterator->match("</$tag>") )
                {
                    return;
                }
                else
                {
                $pos=$iterator->getPos();
                    $section=new HTMLParserSectionTag($iterator);
                    if( $section->type==HTMLParserTag_STANDALONE && strtolower($section->value)==$tag )
                    {
                        return;
                    }
                    else
                    {
                        $iterator->setPos($pos);
                        $this->value.=$iterator->getChar();
                    }
                }
            }   
        }
        function getAttribute( $name )
        {
            return array_key_exists($name,$this->attrs)?$this->attrs[$name]:null;
        }
        function readAttrs(&$iterator)
        {
            while( $iterator->hasMore() )
            {
                if( $iterator->match( '>' ) )
                {
                    return '>';
                }
                else if( $iterator->match( '/>' ) )
                {
                    return '/>';
                }
                $iterator->skipWhiteSpace();
                $name='';
                $value='';
                $ch=$iterator->getChar();
                while( $ch!='' && !isWhiteSpace($ch) && $ch!='>' && $ch!='=' )
                {
                    if( $ch=='/' && $iterator->peek()=='>')
                    {
                        $ch='/>';
                        $iterator->getChar();
                        break;
                    }
                    $name.=$ch;
                    $ch=$iterator->getChar();
                }
                if( $ch=='>' || $ch=='/>')
                {
                    $this->attrs[$name]=false;
                    return $ch;
                }
                $whitespace=(isWhiteSpace($ch)?1:0)+$iterator->skipWhiteSpace();
                if( $iterator->peek()=='=' )
                {
                    $ch='=';
                    $iterator->skip();
                    $whitespace=0;
                }
                $whitespace=$whitespace+$iterator->skipWhiteSpace();
                $value=false;
                if( $iterator->peek()=='\'' )
                {
                    $iterator->skip();
                    $ch=$iterator->getChar();
                    while( $ch!='\'' )
                    {
                        $value.=$ch;
                        $ch=$iterator->getChar();
                    }
                }
                else if( $iterator->peek()=='"' )
                {
                    $iterator->skip();
                    $ch=$iterator->getChar();
                    while( $ch!='"' )
                    {
                        $value.=$ch;
                        $ch=$iterator->getChar();
                    }
    
                }
                else
                {
                    if( $whitespace==0 )
                    {
                        $value='';
                        $ch=$iterator->getChar();
                        while( $ch!='' && !isWhiteSpace($ch) && $ch!='>' && $ch!='=' )
                        {
                            if( $ch=='/' && $iterator->peek()=='>')
                            {
                                $ch='/>';
                                $iterator->getChar();
                                break;
                            }
                            $value.=$ch;
                            $ch=$iterator->getChar();
                        }
                        if( $ch=='>' || $ch=='/>')
                        {
                            $this->attrs[$name]=$value;
                            return $ch;
                        }
                    }
                }
                if( $name!='' )
                {
                    $this->attrs[$name]=$value;
                }
    
    
            }
        }
        function isEntirelyWhiteSpace()
        {
            if( count($this->attrs)==0 )
            {
                for( $i=0;$i<strlen($this->value);$i++)
                {
                    if( !isWhiteSpace($this->value[$i]) )
                    {
                        return false;
                    }
                }
                return true;
            }
            else
            {
                return false;
            }
        }
        /*
        define("HTMLParserTag_CONTENT",0);
    define("HTMLParserTag_OPEN",1);
    define("HTMLParserTag_CLOSE",2);
    define("HTMLParserTag_STANDALONE",3);
    define("HTMLParserTag_COMMENT",4);
    define("HTMLParserTag_EXTENDED_COMMENT",5);
    define("HTMLParserTag_SCRIPT",6);
    define("HTMLParserTag_STYLE",7);
    define("HTMLParserTag_TEXTAREA",8);
    */
        function getAttributesText()
        {
            $out='';
            foreach( $this->attrs as $name=>$value )
            {
                $out.=' '.$name;
                if( $value!==false)
                {
                    $out.='="'.str_replace('"','&#34;',$value ).'"';
                }
            }
            return $out;
        }
        function getContent()
        {
            $out='';
            switch( $this->type)
            {
                case HTMLParserTag_CONTENT:
                {
                    $out=$this->value;
                }
                break;
                case HTMLParserTag_OPEN:
                case HTMLParserTag_STANDALONE:
                {
                    $out='<'.$this->value;
                    $attr=$this->getAttributesText();
                    if( $attr!='')
                    {
                        $out.=$attr.' ';
                    }
                    $out.=$this->type==HTMLParserTag_STANDALONE?'/>':'>';
                }
                break;
                case HTMLParserTag_CLOSE:
                {
    
                    $out='</'.$this->value.">";
                }
                break;
                case HTMLParserTag_SCRIPT:
                {
                    $out='<script';
                    $attr=$this->getAttributesText();
                    if( $attr!='')
                    {
                        $out.=$attr.' ';
                    }
                    $out.='>'.$this->value."</script>";
                }
                break;
                case HTMLParserTag_TEXTAREA:
                {
                    $out='<textarea';
                    $attr=$this->getAttributesText();
                    if( $attr!='')
                    {
                        $out.=$attr.' ';
                    }
                    $out.='>'.$this->value."</textarea>";
                }
                break;
                case HTMLParserTag_STYLE:
                {
                    $out='<style';
                    $attr=$this->getAttributesText();
                    if( $attr!='')
                    {
                        $out.=$attr.' ';
                    }
                    $out.='>'.$this->value."</style>";
                }
                break;
                case HTMLParserTag_COMMENT:
                {
                    $out.='<!'.$this->value.">";
                }
                break;
                case HTMLParserTag_EXTENDED_COMMENT:
                {
                    $out.='<!--'.$this->value."-->";
                }
                break;
            }
            return $out;
        }
        function hasTagName( $name )
        {
            $out=false;
            switch( $this->type)
            {
                case HTMLParserTag_OPEN:
                case HTMLParserTag_STANDALONE:
                case HTMLParserTag_CLOSE:
                {
                    $out=strtolower($this->value)==strtolower($name);
                }
                break;
                case HTMLParserTag_SCRIPT:
                {
                    $out=strtolower($name)=='script';
                }
                break;
                case HTMLParserTag_TEXTAREA:
                {
                    $out=strtolower($name)=='textarea';
                }
                break;
                case HTMLParserTag_STYLE:
                {
                    $out=strtolower($name)=='style';
                }
                break;
                case HTMLParserTag_COMMENT:
                case HTMLParserTag_EXTENDED_COMMENT:
                {
                    if( strtolower($name)=='~comment' )
                    {
                        $out=true;
                    }
                    else if( sWith(strtolower($name),'~comment:' ) )
                    {
                        $out=$this->value==substr($name,strlen('~comment:'));
                    }
                }
                break;
                case HTMLParserTag_CONTENT:
                {
                    $out=strtolower($name)=='~content';
                }
                break;
                default:
                {
                    $out=false;
                }
                break;
            }
            return $out;
        }
        function removeAttributes( $name )
        {
            $newAttrs=Array();
            $name=strtolower($name);
            foreach( $this->attrs as $attrName=>$attrValue )
            {
                if( strtolower($name)!=strtolower($attrName) )
                {
                    $newAttrs[$attrName]=$attrValue;
                }
            }
            $this->attrs=$newAttrs;
        }
        function removeAttributesStartingWith( $name )
        {
            $newAttrs=Array();
            $name=strtolower($name);
            foreach( $this->attrs as $attrName=>$attrValue )
            {
                if( !sWith(strtolower($attrName),strtolower($name)) )
                {
                    $newAttrs[$attrName]=$attrValue;
                }
            }
            $this->attrs=$newAttrs;
        }   
        function removeStyle( $name )
        {
            $name=strtolower($name);
            $styleKey='';
            foreach( $this->attrs as $attrName=>$attrValue )
            {
                if( strtolower($attrName)=='style' )
                {
                    $styleKey=$attrName;
                }
            }
            if( $styleKey!='' )
            {
                $styleDef=new HTMLParserIteratorStyleDefintion( $this->attrs[$styleKey] );
                $styleDef->removeStyle($name);
                $this->attrs[$styleKey]=$styleDef->getContent();
            }
        }
        function removeStyleStartingWith( $name )
        {
            $name=strtolower($name);
            $styleKey='';
            foreach( $this->attrs as $attrName=>$attrValue )
            {
                if( strtolower($attrName)=='style' )
                {
                    $styleKey=$attrName;
                }
            }
            if( $styleKey!='' )
            {
                $styleDef=new HTMLParserIteratorStyleDefintion( $this->attrs[$styleKey] );
                $styleDef->removeStyleStartingWith($name);
                $this->attrs[$styleKey]=$styleDef->getContent();
            }
        }
        function replaceSources( $srcs )
        {
    
            foreach($this->attrs as $name=>$val )
            {
                if(strtolower($name)=='src' && array_key_exists($val,$srcs ))
                {
                    $this->attrs[$name]=$srcs[$val];
                }
            }
        }
        function getSources(&$srcs)
        {
            foreach($this->attrs as $name=>$val )
            {
                if(strtolower($name)=='src' )
                {
                    $srcs[$this->attrs[$name]]=true;
                }
            }
        }
    }
    
    
    class HTMLParser
    {
        var $sections=Array();
        function HTMLParser( $contents )
        {
            $iterator=new HTMLParserIterator($contents);
            $this->sections=Array();
            while( $iterator->hasMore() )
            {
    
                $startPos=$iterator->getPos();
                $section=new HTMLParserSectionTag($iterator);
                $this->sections[]=$section;
                if( $startPos==$iterator->getPos() )
                {
                    break;
                }
            }
        }
        function getContent()
        {
            $out='';
            foreach( $this->sections as $section )
            {
                $out.=$section->getContent();
            }
            return $out;
        }
        function removeTags( $name )
        {
            $newSections=Array();
            foreach( $this->sections as $section )
            {
                if( !$section->hasTagName($name) )
                {
                    $newSections[]=$section;
                }
            }
            $this->sections=$newSections;
        }
        function removeAttributes( $name )
        {
            for( $i=0;$i<count($this->sections);$i++)
            {
                $this->sections[$i]->removeAttributes($name);
            }
        }
        function removeAttributesStartingWith( $name )
        {
            for( $i=0;$i<count($this->sections);$i++)
            {
                $this->sections[$i]->removeAttributesStartingWith($name);
            }
        }
        function removeStyle( $name )
        {
            for( $i=0;$i<count($this->sections);$i++)
            {
                $this->sections[$i]->removeStyle($name);
            }
        }
        function removeStyleStartingWith( $name )
        {
            for( $i=0;$i<count($this->sections);$i++)
            {
                $this->sections[$i]->removeStyleStartingWith($name);
            }
        }
        function removeSections( $name )
        {
            $newSections=Array();
            $openTags=0;
            foreach( $this->sections as $section )
            {
                if( !$section->hasTagName($name) )
                {
                    if( $openTags==0 )
                    {
                        $newSections[]=$section;
                    }
                }
                else
                {
                    if( $section->type==HTMLParserTag_OPEN )
                    {
                        $openTags++;
                    }
                    else if( $section->type==HTMLParserTag_CLOSE && $openTags>0)
                    {
                        $openTags--;
                    }
                }
            }
            $this->sections=$newSections;
        }
        function replaceSources( $srcs )
        {
            foreach( $this->sections as $id=>$section )
            {
                $this->sections[$id]->replaceSources( $srcs );  
            }
        }
        function moveSources( $basePath,$oldFolder,$newFolder )
        {
            $srcs=$this->getSources();
            $newSrcs=Array();
            foreach($srcs as $src=>$junk )
            {
                if( substr( $src,0,strlen($oldFolder) )==$oldFolder )
                {
                    if( !file_exists($basePath.$newFolder ) )
                    {
                        mkdir($basePath.$newFolder );
                    }
                    $newSrc=$newFolder.substr( $src,strlen($oldFolder) );
                    rename($basePath.$src,$basePath.$newSrc);
                    $newSrcs[$src]=$newSrc;
    
                }
            }
            $this->replaceSources( $newSrcs );
        }
        function getSources()
        {
            $srcs=Array();
            foreach( $this->sections as $id=>$section )
            {
                $this->sections[$id]->getSources( $srcs) ;  
            }
            return $srcs;
        }
        function compact( )
        {
            $newSections=Array();
            $openTags=0;
            foreach( $this->sections as $section )
            {
                if( !$section->isEntirelyWhiteSpace() )
                {
                    $newSections[]=$section;
                }
            }
            $this->sections=$newSections;
        }
    
        function removeUpto( $name, $inclusive=false)
        {
            $newSections=Array();
            $found=false;
            foreach( $this->sections as $section )
            {
                if( !$inclusive && $section->hasTagName($name) )
                {
                    $found=true;
                }
                if( $found)
                {
                    $newSections[]=$section;
                }
                if( $inclusive && $section->hasTagName($name) )
                {
                    $found=true;
                }
            }
            $this->sections=$newSections;
        }
        function removeAfter( $name, $inclusive=false)
        {
            $newSections=Array();
            $found=false;
            foreach( $this->sections as $section )
            {
                if( $inclusive && $section->hasTagName($name) )
                {
                    $found=true;
                }
                if( !$found)
                {
                    $newSections[]=$section;
                }
                if( !$inclusive && $section->hasTagName($name) )
                {
                    $found=true;
                }
            }
            $this->sections=$newSections;
        }
    }
    
    
    ?>
    

    EDIT: This is actually the part you want, the part above parses the HTML emails.

    <?php
    define('ATTACHMENT_UPLOAD_SERVER_DIRECTORY',dirname(__FILE__).'/storedimages');
    define('ATTACHMENT_UPLOAD_WEB_DIRECTORY','storedimages');
        if( !function_exists('randomString') )
        {
            function randomString( $len,$chrs='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789')
            {
              $out="";
              for($i=0;$i<$len;$i++)
              {
                $out=$out.substr($chrs,rand()%strlen($chrs),1);
            }
            return $out;
          }
        }
    class EmailDownloader
    {
        var $imageTypesAllowed=Array('JPEG'=>'.jpg','GIF'=>'.gif','PNG'=>'.png');
        var $mbox           =   NULL;   /* mailbox resource */
        function EmailDownloader($username,$password,$mailserver='localhost',$servertype='pop',$port='default')
        {
            if($port=='default')
            {
                $imap_port='143';
                $pop_port='110';
            }
            else
            {
                $imap_port=$port;
                $pop_port=$port;
            }
            if($servertype=='pop')
            {
                 $strconnect= '{'.$mailserver.':'.$pop_port. '/pop3}INBOX';
            }
            else if($servertype=='imap') 
            {
                $strconnect= $strconnect='{'.$mailserver.':'.$imap_port. '}INBOX'; 
            }
            else 
            {
                die("*** error, mailserver type should be either 'pop' or 'imap'\n");
            }
            $this->mbox=imap_open($strconnect,$username,$password);
        }
        function getEmails($deleteMessages=false,$attachmentLocationServer=ATTACHMENT_UPLOAD_SERVER_DIRECTORY,$attachmentLocationWeb=ATTACHMENT_UPLOAD_WEB_DIRECTORY)
        {
            $headers=imap_headers($this->mbox);
            //print_r($headers);
            $emails=Array();
    
            for($idx=0,$mid=1;$idx<count($headers);$idx++,$mid++)
            {   
                $tmpFolder='';
                while ($tmpFolder=='' )
                {
                    $tmpFolder='/tmp_'.randomString( 5,'abcdefghijklmnopqrstuvwxyz0123456789');
                    if( file_exists($attachmentLocationServer.$tmpFolder) )
                    {
                        $tmpFolder='';
                    }
                }
                mkdir($attachmentLocationServer.$tmpFolder );
    
                $images=Array();
                $mail_header=imap_header($this->mbox,$mid);
                $fromAddress=($mail_header->from[0]->mailbox).'@'.($mail_header->from[0]->host);
                //print_r($mail_header);
                // $message=imap_body($this->mbox,$mid); # yeah, not so simple, some voodoo needed
                $mob=imap_fetchstructure($this->mbox,$mid);
                if(($mob->type)==0)
                {
                    // simple text message so, no problemo!
                    $message=imap_body($this->mbox,$mid);
                }else
                {
                    // oops, multipart message
                //  echo  get_part($this->mbox, $mid, "MULTIPART");
                    $contentParts = count($mob->parts);
                    $message=get_part($this->mbox, $mid, "TEXT/HTML", $mob);
                    foreach( $mob->parts as $nm=>$part )
                    {
                        if( $part->type==5  ||$part->type==3 )
                        {
                            $ext='';
                            if( array_key_exists($part->subtype,$this->imageTypesAllowed) )
                            {
                                $ext=$this->imageTypesAllowed[$part->subtype];
                            }
                            if( $ext=='' && $part->subtype=='OCTET-STREAM' && isset($part->dparameters) )
                            {
                                $attFilename='';
                                foreach( $part->dparameters as $dpara )
                                {
                                    if( $dpara->attribute=='FILENAME' ) 
                                    {
                                        $attFilename=$dpara->value;
                                    }
                                }
                                foreach( $this->imageTypesAllowed as $allowedExt )
                                {
                                    if( substr($attFilename,-strlen($allowedExt) )== $allowedExt )
                                    {
                                        $ext=$allowedExt;
                                    }
                                }
                            }
                            if( $ext!=''  )
                            {
                                $filename='';
                                while(  $filename=='' )
                                {
                                    $filename=randomString( 20,'abcdefghijklmnopqrstuvwxyz0123456789').$ext;
                                    if( file_exists($attachmentLocationServer.$tmpFolder.'/'.$filename ) )
                                    {
                                        $filename='';
                                    }
                                }
                                if( $file=fopen($attachmentLocationServer.$tmpFolder.'/'.$filename,'w') )
                                {
                                    fwrite($file,imap_base64(imap_fetchbody($this->mbox,$mid,$nm+1)));
                                    fclose($file);
                                    $images[str_replace(array('>','<'),array('','cid:'),$part->id)]=$attachmentLocationWeb.$tmpFolder.'/'.$filename;
                                }
    
                            }
    
                        }
                    }
    
                }
                $emails[]=Array('from'=>$fromAddress,'subject'=>$mail_header->Subject,'body'=>$message,'header'=>$mail_header,'images'=>$images,'tmp_folder'=>$tmpFolder);
                if( $deleteMessages )
                {
                    imap_delete($this->mbox,$mid);      
                }
            }
            imap_expunge($this->mbox);
            return $emails;
        }
    
        function close()
        {
            imap_close($this->mbox);
        }
    }
    ?>
    
    
    
    <?
       function get_mime_type(&$structure) {
       $primary_mime_type = array("TEXT", "MULTIPART","MESSAGE", "APPLICATION", "AUDIO","IMAGE", "VIDEO", "OTHER");
       if($structure->subtype) {
        return $primary_mime_type[(int) $structure->type] . '/' .$structure->subtype;
       }
        return "TEXT/PLAIN";
       }
       function get_part($stream, $msg_number, $mime_type, $structure = false,$part_number    = false) {
    
        if(!$structure) {
            $structure = imap_fetchstructure($stream, $msg_number);
        }
        if($structure) {
            if($mime_type == get_mime_type($structure)) {
                if(!$part_number) {
                    $part_number = "1";
                }
                $text = imap_fetchbody($stream, $msg_number, $part_number);
                if($structure->encoding == 3) {
                    return imap_base64($text);
                } else if($structure->encoding == 4) {
                    return imap_qprint($text);
                } else {
                return $text;
            }
        }
    
            if($structure->type == 1) /* multipart */
            {
                $prefix ='';
            while(list($index, $sub_structure) = each($structure->parts)) {
                if($part_number) {
                    $prefix = $part_number . '.';
                }
                $data = get_part($stream, $msg_number, $mime_type, $sub_structure,$prefix .    ($index + 1));
                if($data) {
                    return $data;
                }
            } // END OF WHILE
            } // END OF MULTIPART
        } // END OF STRUTURE
        return false;
       } // END OF FUNCTION
    
    ?> 
    

    EDIT #2: One More Part to complete the entire process

    <?php
    
        define('RECEIVING_EMAIL_SERVER','mail.server.com');
        define('RECEIVING_EMAIL_ACCOUNT','incoming@server.com');
        define('RECEIVING_EMAIL_PASSWORD','myPasswordIsHere');
        define('DELETE_MAIL_MESSAGES_FROM_SERVER',false);
        define('USE_MYSQL_ESCAPE',false);
        define('STORED_FOLDER_BASE',dirname(__FILE__).'/');
        define('STORED_IMAGES_LOCATION','storedimages');
        define('STORED_IMAGES_LOCATION_ABSOLUTE',STORED_FOLDER_BASE.STORED_IMAGES_LOCATION);
        include_once('class.emaildownloader.php');
        include_once('class.htmlparser.php');
        $getEmail=new EmailDownloader(RECEIVING_EMAIL_ACCOUNT,RECEIVING_EMAIL_PASSWORD,RECEIVING_EMAIL_SERVER);
        $emails=$getEmail->getEmails( DELETE_MAIL_MESSAGES_FROM_SERVER,STORED_IMAGES_LOCATION_ABSOLUTE,STORED_IMAGES_LOCATION );
        $getEmail->close();
    
        if( $emails )
        {   
    echo "EMAILS FOUND: ".count($emails)." <br />";
        }
    
        foreach( $emails as $email )
        {
    echo "PARSING EMAIL<br />";
            $parsedDoc=new HTMLParser($email['body']);
            $parsedDoc->removeSections( "script" );
            $parsedDoc->removeSections( "style" );
            $parsedDoc->removeSections( "head" );
            $parsedDoc->removeSections( "applet");
            $parsedDoc->removeSections( "embed");
            $parsedDoc->removeSections( "object");
            $parsedDoc->removeSections( "iframe" );
            $parsedDoc->removeSections( "select" );
            $parsedDoc->removeSections( "option" );
            $parsedDoc->removeTags("noscript");
            $parsedDoc->removeTags("html");
            $parsedDoc->removeTags("body");
            $parsedDoc->removeTags("~comment");
            $parsedDoc->removeTags( "input" );
            $parsedDoc->removeTags( "link" );
            $parsedDoc->removeTags( "form");
            $parsedDoc->removeAttributes("background");
            $parsedDoc->removeAttributes("bgcolor");
            $parsedDoc->removeAttributesStartingWith("on");
            $parsedDoc->removeStyleStartingWith('background');
            $parsedDoc->compact( );
            if( count($email['images'])>0 ) 
            {
                $parsedDoc->replaceSources( $email['images'] );
            }
            $subject=explode(' ',$email['subject']);
            if( USE_MYSQL_ESCAPE)
            {
                $project_id=mysql_real_escape_string($subject[0]);
                $page_id=mysql_real_escape_string($subject[1]);
            }
            else
            {
                $project_id=addSlashes($subject[0]);
                $page_id=addSlashes($subject[1]);
            }
    
    echo "PARSING COMPLETE<br />";
        }   
    
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
I have a French site that I want to parse, but am running into
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I am currently running into a problem where an element is coming back from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.