Ejemplo n.º 1
3
 function getAttachments($id, $path)
 {
     $parts = imap_fetchstructure($this->mailbox, $id);
     $attachments = array();
     //FIXME if we do an is_array() here it breaks howver if we don't
     //we get foreach errors
     foreach ($parts->parts as $key => $value) {
         $encoding = $parts->parts[$key]->encoding;
         if ($parts->parts[$key]->ifdparameters) {
             $filename = $parts->parts[$key]->dparameters[0]->value;
             $message = imap_fetchbody($this->mailbox, $id, $key + 1);
             switch ($encoding) {
                 case 0:
                     $message = imap_8bit($message);
                 case 1:
                     $message = imap_8bit($message);
                 case 2:
                     $message = imap_binary($message);
                 case 3:
                     $message = imap_base64($message);
                 case 4:
                     $message = quoted_printable_decode($message);
                 case 5:
                 default:
                     $message = $message;
             }
             $fp = fopen($path . $filename, "w");
             fwrite($fp, $message);
             fclose($fp);
             $attachments[] = $filename;
         }
     }
     return $attachments;
 }
Ejemplo n.º 2
2
 public function fetch($delete = false)
 {
     $oImap = imap_open('{' . $this->mail_server . ':993/imap/ssl/notls/novalidate-cert}', $this->username, $this->password);
     $oMailboxStatus = imap_check($oImap);
     $aMessages = imap_fetch_overview($oImap, "1:{$oMailboxStatus->Nmsgs}");
     $validMessages = array();
     foreach ($aMessages as $oMessage) {
         print "Trying message '" . $oMessage->subject . "'";
         $fileContent = $fileType = '';
         $geocoder = factory::create('geocoder');
         $postCode = $geocoder->extract_postcode($oMessage->subject);
         $fromName = null;
         $fromEmail = null;
         if (strpos($oMessage->from, '<')) {
             $split = split('<', $oMessage->from);
             //name - make sure name not an email address
             $fromName = trim($split[0]);
             if (valid_email($fromName)) {
                 $fromName = null;
             }
             //email
             $fromEmail = trim(str_replace('>', '', $split[1]));
         } else {
             $fromEmail = $oMessage->from;
         }
         $images = array();
         $messageStructure = imap_fetchstructure($oImap, $oMessage->msgno);
         if (isset($messageStructure->parts)) {
             $partNumber = 0;
             foreach ($messageStructure->parts as $oPart) {
                 $partNumber++;
                 if ($oPart->subtype == 'PLAIN' && !$postCode) {
                     $messageContent = imap_fetchbody($oImap, $oMessage->msgno, $partNumber);
                     if ($oPart->encoding == 4) {
                         $messageContent = quoted_printable_decode($messageContent);
                     }
                     $postCode = geocoder::extract_postcode($messageContent);
                 } elseif ($oPart->encoding == 3 && in_array($oPart->subtype, array('JPEG', 'PNG'))) {
                     $oImage = null;
                     $encodedBody = imap_fetchbody($oImap, $oMessage->msgno, $partNumber);
                     $fileContent = base64_decode($encodedBody);
                     $oImage = imagecreatefromstring($fileContent);
                     if (imagesx($oImage) > $this->min_import_size && imagesy($oImage) > $this->min_import_size) {
                         array_push($images, $oImage);
                     }
                     $fileType = strtolower($oPart->subtype);
                 }
             }
         }
         //add to the messages array
         array_push($validMessages, array('postcode' => $postCode, 'images' => $images, 'file_type' => $fileType, 'from_address' => $fromAddress, 'from_email' => $fromEmail, 'from_name' => $fromName));
         if ($delete) {
             imap_delete($oImap, $oMessage->msgno);
         }
     }
     imap_close($oImap, CL_EXPUNGE);
     $this->messages = $validMessages;
 }
Ejemplo n.º 3
0
 public static function decode($str, $isHeader = true)
 {
     if ($isHeader) {
         $str = str_replace("_", " ", $str);
     }
     return quoted_printable_decode($str);
 }
Ejemplo n.º 4
0
 /**
  * Returns the ezcMailText part corresponding to the parsed message.
  *
  * @return ezcMailText
  */
 public function finish()
 {
     $charset = "us-ascii";
     // RFC 2822 default
     if (isset($this->headers['Content-Type'])) {
         preg_match('/\\s*charset\\s?=\\s?"?([^;"\\s]*);?/', $this->headers['Content-Type'], $parameters);
         if (count($parameters) > 0) {
             $charset = strtolower(trim($parameters[1], '"'));
         }
     }
     $encoding = strtolower($this->headers['Content-Transfer-Encoding']);
     if ($encoding == ezcMail::QUOTED_PRINTABLE) {
         $this->text = quoted_printable_decode($this->text);
     } else {
         if ($encoding == ezcMail::BASE64) {
             $this->text = base64_decode($this->text);
         }
     }
     $this->text = ezcMailCharsetConverter::convertToUTF8($this->text, $charset);
     $part = new ezcMailText($this->text, 'utf-8', ezcMail::EIGHT_BIT, $charset);
     $part->subType = $this->subType;
     $part->setHeaders($this->headers->getCaseSensitiveArray());
     ezcMailPartParser::parsePartHeaders($this->headers, $part);
     $part->size = strlen($this->text);
     return $part;
 }
Ejemplo n.º 5
0
 public static function decode($data, $charset, &$o, &$attachments, $options = array())
 {
     //$body= iconv(strtoupper($charset),'UTF-8',$data);
     //return $body;
     $data = quoted_printable_decode($data);
     // utf8_decode(imap_utf8($data)));
     //print ($data);
     //$data = iconv(strtoupper($charset),'CP1250//IGNORE',$data);
     $ical = new iCalReader($data, 'string');
     $arr = $ical->events();
     $body = array('ATTENDEE' => array(), 'ORGANIZER' => array());
     if (is_array($arr) && array_key_exists(0, $arr) && is_array($arr[0])) {
         foreach ($arr[0] as $k => $v) {
             $sk = explode(';', $k);
             $p = array();
             for ($i = 1; $i < count($sk); $i++) {
                 $t = explode('=', $sk[$i], 2);
                 $p[$t[0]] = $t[1];
             }
             $p['VALUE'] = stripslashes($v);
             switch ($sk[0]) {
                 case 'ORGANIZER':
                 case 'ATTENDEE':
                     $body[$sk[0]][] = $p;
                     break;
                 default:
                     $body[$sk[0]] = $p;
                     break;
             }
         }
     }
     //db($arr);
     //db($body);
     return $body;
 }
Ejemplo n.º 6
0
 /**
  * Parce httml attach images
  */
 public function buildHtml()
 {
     // Important, without this line the example don't work!
     // The images will be attached to the email but these will be not
     // showed inline
     $this->setType(Zend_Mime::MULTIPART_RELATED);
     $zend_mime_part = $this->getBodyHtml();
     $html = quoted_printable_decode($zend_mime_part->getContent());
     $matches = array();
     preg_match_all("#<img.*?src=['\"]([^'\"]+)#i", $html, $matches);
     $matches = array_unique($matches[1]);
     if (count($matches) > 0) {
         foreach ($matches as $key => $filename) {
             if (is_readable($filename)) {
                 $at = new Zend_Mime_Part(file_get_contents($filename));
                 $at->type = $this->mimeByExtension($filename);
                 $at->disposition = Zend_Mime::DISPOSITION_INLINE;
                 $at->encoding = Zend_Mime::ENCODING_BASE64;
                 $at->id = 'cid_' . md5_file($filename);
                 $html = str_replace($filename, 'cid:' . $at->id, $html);
                 $this->addAttachment($at);
             }
         }
         $this->setBodyHtml($html, 'UTF-8', Zend_Mime::ENCODING_8BIT);
     }
 }
 public function testEncodingAndDecodingSamples()
 {
     $sampleFp = opendir($this->_samplesDir);
     while (false !== ($encodingDir = readdir($sampleFp))) {
         if (substr($encodingDir, 0, 1) == '.') {
             continue;
         }
         $sampleDir = $this->_samplesDir . '/' . $encodingDir;
         if (is_dir($sampleDir)) {
             $fileFp = opendir($sampleDir);
             while (false !== ($sampleFile = readdir($fileFp))) {
                 if (substr($sampleFile, 0, 1) == '.') {
                     continue;
                 }
                 $text = file_get_contents($sampleDir . '/' . $sampleFile);
                 $os = new Swift_ByteStream_ArrayByteStream();
                 $os->write($text);
                 $is = new Swift_ByteStream_ArrayByteStream();
                 $this->_encoder->encodeByteStream($os, $is);
                 $encoded = '';
                 while (false !== ($bytes = $is->read(8192))) {
                     $encoded .= $bytes;
                 }
                 $this->assertEquals(quoted_printable_decode($encoded), preg_replace('~\\r(?!\\n)|(?<!\\r)\\n~', "\r\n", $text), '%s: Encoded string should decode back to original string for sample ' . $sampleDir . '/' . $sampleFile);
             }
             closedir($fileFp);
         }
     }
     closedir($sampleFp);
 }
Ejemplo n.º 8
0
 public function testStreamEncoding()
 {
     $testfile = realpath(__FILE__);
     $original = file_get_contents($testfile);
     // Test Base64
     $fp = fopen($testfile, 'rb');
     $this->assertTrue(is_resource($fp));
     $part = new Mime\Part($fp);
     $part->encoding = Mime\Mime::ENCODING_BASE64;
     $fp2 = $part->getEncodedStream();
     $this->assertTrue(is_resource($fp2));
     $encoded = stream_get_contents($fp2);
     fclose($fp);
     $this->assertEquals(base64_decode($encoded), $original);
     // test QuotedPrintable
     $fp = fopen($testfile, 'rb');
     $this->assertTrue(is_resource($fp));
     $part = new Mime\Part($fp);
     $part->encoding = Mime\Mime::ENCODING_QUOTEDPRINTABLE;
     $fp2 = $part->getEncodedStream();
     $this->assertTrue(is_resource($fp2));
     $encoded = stream_get_contents($fp2);
     fclose($fp);
     $this->assertEquals(quoted_printable_decode($encoded), $original);
 }
Ejemplo n.º 9
0
function Encoding_check($structure, $msg)
{
    if ($structure->encoding == 3) {
        //echo "encoding type is 3 </br>";
        /*$msg= "<div>" .base64_decode($msg). "</div>";
          echo "$msg </br>";*/
        return print_msg_content(base64_decode($msg));
    } else {
        if ($structure->encoding == 4) {
            // echo "encoding type is 4 </br>";
            // $msg = "<div>" .quoted_printable_decode($msg). "</div>";
            //$text = imap_utf7_decode($text);
            //echo "$msg </br></br>";
            return print_msg_content(quoted_printable_decode($msg));
        } else {
            if ($structure->encoding == 0) {
                //echo "encoding type is 0 </br>";
                //$text = decode7Bit($text);
                // echo "<div>" .$msg. "</div></br>";
                return print_msg_content($msg);
            } else {
                if ($structure->encoding == 1) {
                    // echo "encoding type is 1 </br>";
                    /*echo "<div>" .$msg. "</div></br>";*/
                    return print_msg_content($msg);
                } else {
                    echo "Some other encoding format of type " . $structure->encoding . "</br>";
                }
            }
        }
    }
}
 public function testEncodingAndDecodingSamplesFromDiConfiguredInstance()
 {
     $sampleFp = opendir($this->_samplesDir);
     while (false !== ($encodingDir = readdir($sampleFp))) {
         if (substr($encodingDir, 0, 1) == '.') {
             continue;
         }
         $encoding = $encodingDir;
         $encoder = $this->_createEncoderFromContainer();
         $sampleDir = $this->_samplesDir . '/' . $encodingDir;
         if (is_dir($sampleDir)) {
             $fileFp = opendir($sampleDir);
             while (false !== ($sampleFile = readdir($fileFp))) {
                 if (substr($sampleFile, 0, 1) == '.') {
                     continue;
                 }
                 $text = file_get_contents($sampleDir . '/' . $sampleFile);
                 $os = new Swift_ByteStream_ArrayByteStream();
                 $os->write($text);
                 $is = new Swift_ByteStream_ArrayByteStream();
                 $encoder->encodeByteStream($os, $is);
                 $encoded = '';
                 while (false !== ($bytes = $is->read(8192))) {
                     $encoded .= $bytes;
                 }
                 $this->assertEquals(str_replace("\r\n", "\n", quoted_printable_decode($encoded)), str_replace("\r\n", "\n", $text), '%s: Encoded string should decode back to original string for sample ' . $sampleDir . '/' . $sampleFile);
             }
             closedir($fileFp);
         }
     }
     closedir($sampleFp);
 }
Ejemplo n.º 11
0
 function getPart($partNumber, $encoding)
 {
     $data = imap_fetchbody($this->connection, $this->messageNumber, $partNumber, FT_UID);
     switch ($encoding) {
         case 0:
             return $data;
             // 7BIT
         // 7BIT
         case 1:
             return $data;
             // 8BIT
         // 8BIT
         case 2:
             return $data;
             // BINARY
         // BINARY
         case 3:
             return base64_decode($data);
             // BASE64
         // BASE64
         case 4:
             return quoted_printable_decode($data);
             // QUOTED_PRINTABLE
         // QUOTED_PRINTABLE
         case 5:
             return $data;
             // OTHER
     }
 }
 function displayNotificationEmail()
 {
     $html = '';
     $html .= '<h3>' . $GLOBALS['Language']->getText('plugin_docman', 'details_approval_email_title') . '</h3>';
     $atsm = new Docman_ApprovalTableNotificationCycle();
     $atsm->setItem($this->item);
     $atf =& Docman_ApprovalTableFactoriesFactory::getFromItem($this->item);
     $table = $atf->getTable(false);
     $atsm->setTable($table);
     $um =& UserManager::instance();
     $owner =& $um->getUserById($table->getOwner());
     $atsm->setOwner($owner);
     $atsm->sendNotifReviewer($owner);
     $html .= $GLOBALS['Language']->getText('plugin_docman', 'details_approval_email_subject') . ' ' . $atsm->getNotificationSubject() . "\n";
     $html .= '<p class="docman_approval_email">';
     if (ProjectManager::instance()->getProject($this->item->getGroupId())->getTruncatedEmailsUsage()) {
         $html .= $GLOBALS['Language']->getText('plugin_docman', 'truncated_email');
     } else {
         $html .= htmlentities(quoted_printable_decode($atsm->getNotificationBodyText()), ENT_COMPAT, 'UTF-8');
     }
     $html .= '</p>';
     $backurl = $this->url . '&action=approval_create&id=' . $this->item->getId();
     $html .= '<a href="' . $backurl . '">' . $GLOBALS['Language']->getText('plugin_docman', 'details_approval_email_back') . '</a>';
     return $html;
 }
Ejemplo n.º 13
0
function simple_page_mode2($numeric_id = true)
{
    global $Ajax, $Mode2, $selected_id2;
    $default = $numeric_id ? -1 : '';
    $selected_id2 = get_post('selected_id2', $default);
    foreach (array('ADD_ITEM2', 'UPDATE_ITEM2', 'RESET2') as $m) {
        if (isset($_POST[$m])) {
            $Ajax->activate('_page_body');
            if ($m == 'RESET2') {
                $selected_id2 = $default;
            }
            $Mode2 = $m;
            return;
        }
    }
    foreach (array('BEd', 'BDel') as $m) {
        foreach ($_POST as $p => $pvar) {
            if (strpos($p, $m) === 0) {
                //				$selected_id2 = strtr(substr($p, strlen($m)), array('%2E'=>'.'));
                unset($_POST['_focus']);
                // focus on first form entry
                $selected_id2 = quoted_printable_decode(substr($p, strlen($m)));
                $Ajax->activate('_page_body');
                $Mode2 = $m;
                return;
            }
        }
    }
    $Mode2 = '';
}
Ejemplo n.º 14
0
 private static function fetchBody($obj, $conn, $folder, $id, $structure, $part)
 {
     $body = $obj->fetchPartBody($conn, $folder, $id, $part);
     $encoding = EmailMimeUtil::getPartEncodingCode($structure, $part);
     if ($encoding == 3) {
         $body = base64_decode($body);
     } elseif ($encoding == 4) {
         $body = quoted_printable_decode($body);
     }
     $charset = EmailMimeUtil::getPartCharset($structure, $part);
     if (empty($charset)) {
         $part_header = $obj->fetchPartHeader($conn, $folder, $id, $part);
         $pattern = "/charset=[\"]?([a-zA-Z0-9_-]+)[\"]?/";
         preg_match($pattern, $part_header, $matches);
         if (count($matches) == 2) {
             $charset = $matches[1];
         }
     }
     if (strcasecmp($charset, "utf-8") == 0) {
         $is_unicode = true;
     } elseif (preg_match("/#[0-9]{5};/", $body)) {
         $is_unicode = false;
     } else {
         $is_unicode = false;
     }
     if (!$is_unicode) {
         $body = ConvertUtil::iIconv($body, "gb2312");
     }
     $url = Yii::app()->urlManager->createUrl("email/web/show", array("webid" => self::$_web["webid"], "folder" => $folder, "id" => $id, "cid" => ""));
     $body = preg_replace("/src=(\")?cid:/i", "src=\"{$url}", $body);
     return $body;
 }
Ejemplo n.º 15
0
 function get_part($ret, $mid, $p, $partno)
 {
     // DECODE DATA
     $data = $partno ? imap_fetchbody($this->con, $mid, $partno) : imap_body($this->con, $mid);
     // simple
     // Any part may be encoded, even plain text messages, so check everything.
     if ($p->encoding == 4) {
         $data = quoted_printable_decode($data);
     } elseif ($p->encoding == 3) {
         $data = base64_decode($data);
     }
     // PARAMETERS
     // get all parameters, like charset, filenames of attachments, etc.
     $params = array();
     if (isset($p->parameters)) {
         foreach ($p->parameters as $x) {
             $params[strtolower($x->attribute)] = $x->value;
         }
     }
     if (isset($p->dparameters)) {
         foreach ($p->dparameters as $x) {
             $params[strtolower($x->attribute)] = $x->value;
         }
     }
     // ATTACHMENT
     // Any part with a filename is an attachment,
     // so an attached text file (type 0) is not mistaken as the message.
     if (!empty($params['filename']) || !empty($params['name'])) {
         // filename may be given as 'Filename' or 'Name' or both
         $filename = empty($params['filename']) ? $params['name'] : $params['filename'];
         // filename may be encoded, so see imap_mime_header_decode()
         $ret->attachments[$filename] = $data;
         // this is a problem if two files have same name
     }
     // TEXT
     if ($p->type == 0 && $data) {
         // Messages may be split in different parts because of inline attachments,
         // so append parts together with blank row.
         if (strtolower($p->subtype) == 'plain') {
             $ret->plainmsg .= trim($data) . "\n\n";
         } else {
             $ret->htmlmsg .= $data . "<br><br>";
         }
         $ret->charset = $params['charset'];
         // assume all parts are same charset
     } elseif ($p->type == 2 && $data) {
         $ret->plainmsg .= $data . "\n\n";
     }
     // SUBPART RECURSION
     if (!empty($p->parts)) {
         foreach ($p->parts as $partno0 => $p2) {
             $subpart = new \stdClass();
             $subpart->htmlmsg = $subpart->plainmsg = $subpart->charset = '';
             $subpart->attachments = array();
             $ret->subpart = $subpart;
             $this->get_part($subpart, $mid, $p2, $partno . '.' . ($partno0 + 1));
             // 1.2, 1.2.1, etc.
         }
     }
 }
Ejemplo n.º 16
0
/**
 * Decode base64 or quoted printable strings.
 *
 * @param string $string
 *   An encoded input string.
 * @param string $dest_encode
 *   Destination character encoding.
 *
 * @return string
 *   The decoded string.
 */
function decode($string, $dest_encode = 'UTF-8')
{
    preg_match('/"([^"]+)"/', $string, $match);
    $parts = preg_split('/=\\?([^?]+)\\?([^?]+)\\?([^?]+)\\?=/i', $string, 0, PREG_SPLIT_DELIM_CAPTURE);
    if (count($parts) == 1) {
        return $string;
    }
    $start_quote = strpos($string, '"');
    $end_quote = strrpos($string, '"');
    $end_string = '';
    if ($start_quote != $end_quote) {
        $end_string = substr($string, $end_quote + 1);
    }
    $decoded = '';
    for ($i = 0; $i < count($parts) - 1; $i += 4) {
        $text = '';
        switch ($parts[$i + 2]) {
            case 'B':
                $text = base64_decode($parts[$i + 3]);
                break;
            case 'Q':
                $text = quoted_printable_decode($parts[$i + 3]);
                break;
        }
        $decoded .= iconv($parts[$i + 1], $dest_encode, $text);
    }
    return $decoded . $end_string;
}
Ejemplo n.º 17
0
 function test_quote_multibyte_chars()
 {
     $original = "æ ø and å";
     $result = AkActionMailerQuoting::quotedPrintableEncode($original);
     $unquoted = quoted_printable_decode($result);
     $this->assertEqual($unquoted, $original);
 }
Ejemplo n.º 18
0
 public function retrieve_message($msgno)
 {
     if (empty($msgno)) {
         exit('no message no.');
     }
     exit(quoted_printable_decode($this->email_model->retrieve_message($msgno)));
 }
 public function testEncodingAndDecodingSamples()
 {
     $sampleFp = opendir($this->_samplesDir);
     while (false !== ($encodingDir = readdir($sampleFp))) {
         if (substr($encodingDir, 0, 1) == '.') {
             continue;
         }
         $encoding = $encodingDir;
         $charStream = new Swift_CharacterStream_ArrayCharacterStream($this->_factory, $encoding);
         $encoder = new Swift_Encoder_QpEncoder($charStream);
         $sampleDir = $this->_samplesDir . '/' . $encodingDir;
         if (is_dir($sampleDir)) {
             $fileFp = opendir($sampleDir);
             while (false !== ($sampleFile = readdir($fileFp))) {
                 if (substr($sampleFile, 0, 1) == '.') {
                     continue;
                 }
                 $text = file_get_contents($sampleDir . '/' . $sampleFile);
                 $encodedText = $encoder->encodeString($text);
                 foreach (explode("\r\n", $encodedText) as $line) {
                     $this->assertLessThanOrEqual(76, strlen($line));
                 }
                 $this->assertEquals(quoted_printable_decode($encodedText), $text, '%s: Encoded string should decode back to original string for sample ' . $sampleDir . '/' . $sampleFile);
             }
             closedir($fileFp);
         }
     }
     closedir($sampleFp);
 }
Ejemplo n.º 20
0
function getpart($mbox, $mid, $p, $partno, $charset, $htmlmsg, $plainmsg, $attachments)
{
    // $partno = '1', '2', '2.1', '2.1.3', etc for multipart, 0 if simple
    // DECODE DATA
    if ($p->encoding != 3 || $partno < 2) {
        $data = $partno ? imap_fetchbody($mbox, $mid, $partno, FT_UID) : imap_body($mbox, $mid, FT_UID);
    }
    // simple
    // Any part may be encoded, even plain text messages, so check everything.
    if ($p->encoding == 4) {
        $data = quoted_printable_decode($data);
    } elseif ($p->encoding == 3) {
        $data = base64_decode($data);
    }
    // PARAMETERS
    // get all parameters, like charset, filenames of attachments, etc.
    $params = array();
    if ($p->parameters) {
        foreach ($p->parameters as $x) {
            $params[strtolower($x->attribute)] = $x->value;
        }
    }
    if ($p->dparameters) {
        foreach ($p->dparameters as $x) {
            $params[strtolower($x->attribute)] = $x->value;
        }
    }
    // ATTACHMENT
    // Any part with a filename is an attachment,
    // so an attached text file (type 0) is not mistaken as the message.
    if ($params['filename'] || $params['name']) {
        // filename may be given as 'Filename' or 'Name' or both
        $filename = $params['filename'] ? $params['filename'] : $params['name'];
        // filename may be encoded, so see imap_mime_header_decode()
        $attachments[$filename] = $data;
        // this is a problem if two files have same name
    }
    // TEXT
    if ($p->type == 0 && $data) {
        // Messages may be split in different parts because of inline attachments,
        // so append parts together with blank row.
        if (strtolower($p->subtype) == 'plain') {
            $plainmsg .= trim($data) . "\n\n";
        } else {
            $htmlmsg .= $data . "<br /><br />";
        }
        $charset = $params['charset'];
        // assume all parts are same charset
    } elseif ($p->type == 2 && $data) {
        $plainmsg .= $data . "\n\n";
    }
    // SUBPART RECURSION
    if ($p->parts) {
        foreach ($p->parts as $partno0 => $p2) {
            list($charset, $htmlmsg, $plainmsg, $attachments) = getpart($mbox, $mid, $p2, $partno . '.' . ($partno0 + 1), $charset, $htmlmsg, $plainmsg, $attachments);
        }
        // 1.2, 1.2.1, etc.
    }
    return array($charset, $htmlmsg, $plainmsg, $attachments);
}
 /**
  * Decodes a MIME encoded string and returns a Zend\Mime\Message object with
  * all the MIME parts set according to the given string
  *
  * @param string $message
  * @param string $boundary
  * @param string $EOL EOL string; defaults to {@link Zend\Mime\Mime::LINEEND}
  * @throws Exception\RuntimeException
  * @return \Zend\Mime\Message
  */
 public static function createFromMessage($message, $boundary, $EOL = Mime::LINEEND)
 {
     $parts = Decode::splitMessageStruct($message, $boundary, $EOL);
     $res = new static();
     foreach ($parts as $part) {
         // now we build a new MimePart for the current Message Part:
         $properties = array();
         foreach ($part['header'] as $header) {
             /** @var \Zend\Mail\Header\HeaderInterface $header */
             /**
              * @todo check for characterset and filename
              */
             $fieldName = $header->getFieldName();
             $fieldValue = $header->getFieldValue();
             switch (strtolower($fieldName)) {
                 case 'content-type':
                     $properties['type'] = $fieldValue;
                     break;
                 case 'content-transfer-encoding':
                     $properties['encoding'] = $fieldValue;
                     break;
                 case 'content-id':
                     $properties['id'] = trim($fieldValue, '<>');
                     break;
                 case 'content-disposition':
                     $properties['disposition'] = $fieldValue;
                     break;
                 case 'content-description':
                     $properties['description'] = $fieldValue;
                     break;
                 case 'content-location':
                     $properties['location'] = $fieldValue;
                     break;
                 case 'content-language':
                     $properties['language'] = $fieldValue;
                     break;
             }
         }
         $body = $part['body'];
         if (isset($properties['encoding'])) {
             switch ($properties['encoding']) {
                 case 'quoted-printable':
                     $body = quoted_printable_decode($body);
                     break;
                 case 'base64':
                     $body = base64_decode($body);
                     break;
             }
         }
         $newPart = new Part($body);
         foreach ($properties as $key => $value) {
             $newPart->{$key} = $value;
         }
         $res->addPart($newPart);
     }
     return $res;
 }
Ejemplo n.º 22
0
function decode_header($charset, $encoding, $text)
{
    if (strtolower($encoding) == "b") {
        $text = base64_decode($text);
    } else {
        $text = quoted_printable_decode($text);
    }
    return to_utf8($text, $charset);
}
Ejemplo n.º 23
0
 /**
  * @depends test_format
  * @covers ::__construct
  */
 public function test_construct()
 {
     $this->FormData = new FormData($this->Fields);
     $Expected = http_build_query(array('field1' => self::TEXT, 'field2' => self::HTML));
     # Check params
     $this->assertTrue(isset($this->FormData['Content']), 'FormData::__construct() failed to set Content');
     $this->assertEquals($Expected . "\r\n", quoted_printable_decode($this->FormData['Content']), 'FormData::__construct() set invalid Content');
     # Invalid arguments
 }
Ejemplo n.º 24
0
 public function testBug9567()
 {
     $text = quoted_printable_decode("pr=E9parer =E0 vendre d’ao=FBt");
     $this->assertEquals($text, Horde_Text_Filter::filter('<html><body>' . $text . '</body></html>', 'xss', array('charset' => 'iso-8859-1')));
     $this->assertEquals($text, Horde_Text_Filter::filter('<html><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></head><body>' . $text . '</body></html>', 'xss', array('charset' => 'iso-8859-1')));
     $text = Horde_String::convertCharset(quoted_printable_decode("pr=E9parer =E0 vendre d&#8217;ao=FBt&nbsp;;"), 'windows-1252', 'UTF-8');
     $expected = "préparer à vendre d’août ;";
     $this->assertEquals($expected, Horde_Text_Filter::filter('<html><body>' . $text . '</body></html>', 'xss', array('charset' => 'utf-8')));
 }
Ejemplo n.º 25
0
 private function doParsePart()
 {
     $headerBag = $this->parseHeaderBag();
     $this->consume("\n");
     $content = $this->consumeAll();
     if ($headerBag->get('Content-Transfer-Encoding') == 'quoted-printable') {
         $content = quoted_printable_decode(rtrim($content, "\n"));
     }
     return array($headerBag, $content);
 }
Ejemplo n.º 26
0
 /**
  * Decodes an encoded value
  * @param string $encoding The encoding used for the value
  * @param string $value The value to decode
  * @return string Decoded value
  */
 public function decodeEncodedValue($encoding, $value)
 {
     if ($encoding == 4 || $encoding == MimePart::ENCODING_QUOTED_PRINTABLE) {
         return quoted_printable_decode($value);
     }
     if ($encoding == 3 || $encoding == MimePart::ENCODING_BASE64) {
         return base64_decode($value);
     }
     return $value;
 }
 private function decodeContentTransfer($input)
 {
     if ($this->getEncoding() == 'base64') {
         return base64_decode($input);
     } elseif ($this->getEncoding() == 'quoted-printable') {
         return quoted_printable_decode($input);
     }
     return $input;
     //8bit, 7bit, binary
 }
 /**
  * Filters the lines in the passed $lines array, returning a concatenated
  * string of decoded lines.
  * 
  * @param array $lines
  * @param int $consumed
  * @return string
  */
 private function filterBucketLines(array $lines, &$consumed)
 {
     $data = '';
     foreach ($lines as $line) {
         $consumed += strlen($line);
         $data .= $line;
     }
     $decoded = quoted_printable_decode($data);
     return $decoded;
 }
Ejemplo n.º 29
0
 public function decode($string, $from)
 {
     if ($from == "base64") {
         return base64_decode($string);
     } elseif ($from == "7bit") {
         return quoted_printable_decode($string);
     } elseif ($from == "quoted-printable") {
         return quoted_printable_decode($string);
     }
     return $string;
 }
Ejemplo n.º 30
0
 /**
  * @param string $raw_message
  *
  * @return Email
  */
 public function parse($raw_message)
 {
     list($headers, $content) = explode("\n\n", $raw_message, 2);
     $data = array('to' => NULL, 'subject' => NULL, 'content' => quoted_printable_decode($content));
     $data['links'] = $this->parseLinksFromContent($data['content']);
     $data['to'] = $this->parseRecipient($headers);
     if (preg_match('/^Subject:\\s+(.+?)$/m', $headers, $matches)) {
         $data['subject'] = $matches[1];
     }
     return new Email($data);
 }