Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: php-mime-mail-parser/php-mime-mail-parser
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: main
Choose a base ref
...
head repository: ProtonMail/php-mime-mail-parser
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: main_230
Choose a head ref
Can’t automatically merge. Don’t worry, you can still create the pull request.
  • 4 commits
  • 5 files changed
  • 1 contributor

Commits on Nov 18, 2024

  1. Copy the full SHA
    c182596 View commit details
  2. ProtonParser: init

    SebTM committed Nov 18, 2024
    Copy the full SHA
    25fbf76 View commit details

Commits on Nov 26, 2024

  1. Merge pull request #1 from ProtonMail/pm_fork

    ProtonMail fork
    SebTM authored Nov 26, 2024
    Copy the full SHA
    4272542 View commit details

Commits on Dec 5, 2024

  1. Add missing getRawHeaders

    SebTM committed Dec 5, 2024
    Copy the full SHA
    6ad7ae0 View commit details
Showing with 984 additions and 7 deletions.
  1. +2 −6 composer.json
  2. +11 −0 src/Enum/BodyType.php
  3. +40 −0 src/Helper/Html.php
  4. +17 −1 src/Parser.php
  5. +914 −0 src/ProtonParser.php
8 changes: 2 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "php-mime-mail-parser/php-mime-mail-parser",
"name": "protonmail/php-mime-mail-parser",
"type": "library",
"description": "Fully Tested Mailparse Extension Wrapper for PHP 5.4+",
"keywords": ["mime", "mail", "mailparse", "MimeMailParser"],
@@ -42,7 +42,7 @@
"url":"https://github.com/php-mime-mail-parser/php-mime-mail-parser.git"
},
"require": {
"php": "^5.4.0 || ^7.0",
"php-64bit": ">=8.2",
"ext-mailparse": "*"
},
"require-dev": {
@@ -51,10 +51,6 @@
"satooshi/php-coveralls": "0.*",
"squizlabs/PHP_CodeSniffer": "2.*"
},
"replace": {
"exorus/php-mime-mail-parser": "*",
"messaged/php-mime-mail-parser": "*"
},
"autoload": {
"psr-4": { "PhpMimeMailParser\\": "src/" }
}
11 changes: 11 additions & 0 deletions src/Enum/BodyType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

declare(strict_types=1);

namespace PhpMimeMailParser\Enum;

enum BodyType: string
{
case Text = 'text';
case Html = 'html';
}
40 changes: 40 additions & 0 deletions src/Helper/Html.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

declare(strict_types=1);

namespace PhpMimeMailParser\Helper;

class Html
{
/**
* Can nest this function and never double-encode.
*
* @param string $input *string to add entities to
* @return string *string with HTML entities
*/
public static function special(string $input): string
{
return htmlspecialchars(htmlspecialchars_decode($input, ENT_QUOTES), ENT_QUOTES);
}

/**
* Make a plain text string html compatible by replacing new lines by html new line tag <br>.
*/
public static function fromPlainText(string $plainText): string
{
$htmlEscapedText = self::special($plainText);

// don't take any risks if string could not be transformed - probably because of the string encoding
if ($htmlEscapedText === '') {
return $plainText;
}

return '<html><body><p>'
. str_replace(
["\r\n", "\r", "\n"],
"<br>\n",
$htmlEscapedText,
)
. '</p></body></html>';
}
}
18 changes: 17 additions & 1 deletion src/Parser.php
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@

namespace PhpMimeMailParser;

use MimeMailParser\Exception\RuntimeException;
use PhpMimeMailParser\Attachment;
use PhpMimeMailParser\Exception;
use PhpMimeMailParser\Contracts\CharsetManager;
@@ -204,6 +205,21 @@ public function getHeaders()
}
}

/**
* Retrieve the raw Email Headers
* @return string
*/
public function getHeadersRaw(): string|array
{
if (isset($this->parts[1])) {
return $this->getPart('headers', $this->parts[1]);
}

throw new \RuntimeException(
'Parser::setPath() or Parser::setText() must be called before retrieving email headers.',
);
}

/**
* Returns the email message body in the specified format
* @return string|false String Body or False if not found
@@ -406,7 +422,7 @@ private function getAttachmentStream(&$part)
* @param string $encodedString The string in its original encoded state
* @param $encodingType The encoding type from the Content-Transfer-Encoding header of the part.
*/
private function decodeContentTransfer($encodedString, $encodingType)
protected function decodeContentTransfer($encodedString, $encodingType)
{
$encodingType = strtolower($encodingType);
if ($encodingType == 'base64') {
Loading