function load($msgnum)
{
$header = imap_header($this->_conn, $msgnum);
$this->address = $this->_from(@$header->from[0]);
$this->subject = JString::trim(@imap_utf8($header->subject));
$this->created = gmdate('Y-m-d H:i:s', $header->udate);
$this->hash = md5(print_r($header, true));
$struct = imap_fetchstructure($this->_conn, $msgnum);
$mime = $this->_mime($struct);
if ($mime == 'TEXT/PLAIN')
{
$body = imap_body($this->_conn, $msgnum);
$this->_parts[] = $this->_part($struct, $body, 1);
} else {
$this->_findParts($struct, $msgnum);
}
$this->content = $this->_getContent();
if ($this->subject == "") {
$this->subject = $this->_getSubjectFromContent();
}
}
function _getContent()
{
if ($this->_config->get('only_subject')) {
return '';
}
$exclude = explode("\n", $this->_config->get('excludetext'));
$content = '';
foreach ($this->getParts('text', 'plain') as $part)
{
$include = true;
foreach ($exclude as $pattern) {
if (trim($pattern) && strpos($part->data, $pattern) !== false) {
$include = false;
}
}
if ($include) {
$content .= nl2br(htmlspecialchars(trim($part->data))) . "<br />\n";
}
}
return $content;
}
function &getParts($type = null, $subtype = null)
{
$parts = array();
foreach ($this->_parts as $part)
{
if ((strtolower($part->type) == strtolower($type) || $type == null) && (strtolower($part->subtype) == strtolower($subtype) || $subtype == null))
{
$parts[] = $part;
}
}
return $parts;
}
function _getSubjectFromContent()
{
$lines = preg_split( '/<br( \/)*>/i', $this->content );
foreach ($lines as $line)
{
$line = JString::trim($line);
if (!empty($line)) {
return $line;
}
}
return JText::_('Untitled');
}
function _from( $from )
{
if( !isset($from) ) {
return null;
}
foreach( $from as $part ) {
if( is_numeric($part) ) {
return ltrim($part, '+0');
}
}
$ret = $from->mailbox . '@' . $from->host;
return imap_utf8( $ret );
}
function _mime ($struct)
{
$primary_mime_type = array('TEXT', 'MULTIPART', 'MESSAGE', 'APPLICATION', 'AUDIO', 'IMAGE', 'VIDEO', 'OTHER');
$type = intval($struct->type);
if( ($type<0) | ($type>=count($primary_mime_type)) ) {
return 'TEXT/PLAIN';
}
if( @$struct->subtype ) {
return strtoupper( $primary_mime_type[$type] . '/' .$struct->subtype );
}
return 'TEXT/PLAIN';
}
function _findParts ($part, $msgnum, $partnum='0')
{
if (is_array(@$part->parts ))
{
for ($i=0; $i<count($part->parts); $i++)
{
$param = $partnum=='0' ? ($i+1) : "$partnum." . ($i+1);
$ret = $this->_findParts( $part->parts[$i], $msgnum, $param );
}
}
else
{
$data = imap_fetchbody( $this->_conn, $msgnum, $partnum );
$this->_parts[] = $this->_part($part, $data, $partnum);
}
}
function _part( $part, $body, $partnum )
{
$ret = new stdClass();
$ret->charset = $this->_parameter( @$part->parameters, 'CHARSET' );
$ret->filename = $this->_parameter( @$part->parameters, 'NAME' );
$ret->mime = $this->_mime( $part );
$type = explode( '/', $ret->mime );
$ret->type = $type[0];
$ret->subtype = $type[1];
$ret->data = $body;
if( !$ret->filename ) {
$ret->filename = $this->_parameter( @$part->dparameters, 'FILENAME' );
}
if( !$ret->filename ) {
$ret->filename = "Part$partnum." . strtolower( $part->subtype );
}
if( $part->encoding == 0 ) { # 7 bit
}
if( $part->encoding == 3 ) {
$ret->data = base64_decode( $ret->data );
}
if( $part->encoding == 4 ) {
$ret->data = quoted_printable_decode( $ret->data );
}
if( !empty($ret->charset) && (strtolower($ret->charset) != 'utf-8') && $ret->type == 'TEXT') {
$ret->data = @iconv($ret->charset, 'utf-8//TRANSLIT', $ret->data);
}
return $ret;
}
function _parameter( $params, $name )
{
if( !is_array( $params ) ) {
return '';
}
for($i=0; $i<count($params); $i++) {
if($params[$i]->attribute == $name) {
return JString::trim(imap_utf8($params[$i]->value));
}
}
return '';
}
}
Registrerte brukere: Google [Bot]