Skip to content

Commit

Permalink
TASK: use less escaping because maildev does it for us, use correct v…
Browse files Browse the repository at this point in the history
…ariables
  • Loading branch information
Christian Keuerleber committed Jan 17, 2025
1 parent 9259ec7 commit 8ca831d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 60 deletions.
13 changes: 4 additions & 9 deletions Classes/ActorTraits/MailDev.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,11 @@ public function iOpenTheSecondMail(): void

/**
* @Then I should see :text in the email
* @Then I should see :text in the email with decodeQP :decodeQuotedPrintableFlag
* @param string $text
* @param bool $decodeQuotedPrintableFlag
*/
public function iSeeInMail(string $text, string|bool $decodeQuotedPrintableFlag = false): void
public function iSeeInMail(string $text): void
{
$this->seeTextInMail($text, $decodeQuotedPrintableFlag);
$this->seeTextInMail($text);
}

/**
Expand All @@ -76,14 +74,11 @@ public function mailIsAddressedTo(string $address): void

/**
* @Then I should see :subject in the email subject
* @Then I should see :subject in the email subject with decodeQP :mimeDecodeFlag
* @Then I should see :subject in the email subject with decodeQP :mimeDecodeFlag and charset :charset
* @param string $subject
* @param bool $mimeDecodeFlag
*/
public function iSeeSubjectOfMail(string $subject, string|bool $mimeDecodeFlag = false, string $charset='UTF-8'): void
public function iSeeSubjectOfMail(string $subject): void
{
$this->seeSubjectOfMail($subject, $mimeDecodeFlag, $charset);
$this->seeSubjectOfMail($subject);
}

/**
Expand Down
10 changes: 4 additions & 6 deletions Classes/Domain/Model/Mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,9 @@ public function __construct(array $mailData)
{
$this->mailData = $mailData;

$this->body = Arrays::getValueByPath($this->maiLData, 'Content.Body');
$this->recipients = Arrays::getValueByPath($this->maiLData, 'Content.Headers.To');
$this->subject = Arrays::getValueByPath($this->maiLData, 'Content.Headers.Subject');


$this->body = Arrays::getValueByPath($this->mailData, 'html');
$this->recipients = Arrays::getValueByPath($this->mailData, 'headers.to');
$this->subject = Arrays::getValueByPath($this->mailData, 'headers.subject');
}

/**
Expand All @@ -72,4 +70,4 @@ public function getRecipients()
{
return $this->recipients;
}
}
}
58 changes: 13 additions & 45 deletions Classes/Module/MailDev.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,16 @@ public function followLinkInTheEmail(string $link): void

/**
* @param string $text
* @param bool $quotedPrintableDecodeFlag
* @throws \Exception
*/
public function seeTextInMail(string $text, bool $quotedPrintableDecodeFlag = false): void
public function seeTextInMail(string $text): void
{
$mail = $this->parseMailBody($this->currentMail->getBody());
if (stristr(self::quotedPrintableDecodeRespectingEquals($mail, $quotedPrintableDecodeFlag), $text)) {
if (stristr(html_entity_decode($mail), $text)) {
return;
}
throw new \Exception(sprintf('Did not find the text "%s" in the mail %s', $text));

throw new \Exception(sprintf('Did not find the text "%s" in the mail', $text));
}

/**
Expand All @@ -124,12 +124,10 @@ public function checkRecipientAddress(string $address): void
*/
public function checkIfSpam(): void
{
$subjectArray = $this->currentMail->getSubject();
$subject = $this->currentMail->getSubject();

foreach ($subjectArray as $subject) {
if (strpos($subject, "[SPAM]") === 0) {
return;
}
if (strpos($subject, "[SPAM]") === 0) {
return;
}

throw new \Exception(sprintf('Could not find [SPAM] at the beginning of subject "%s"', $subject));
Expand All @@ -138,20 +136,17 @@ public function checkIfSpam(): void

/**
* @param string $text
* @param bool $mimeDecodeFlag
* @param string $charset
* @throws \Exception
*/
public function seeSubjectOfMail(string $text, bool $mimeDecodeFlag = false, string $charset = 'UTF-8'): void
public function seeSubjectOfMail(string $text): void
{
$subjectArray = $this->currentMail->getSubject();
$subject = $this->currentMail->getSubject();

foreach ($subjectArray as $subject) {
if (stristr(self::mimeDecodeSubject($subject, $charset), $text)) {
return;
}
if (stristr($subject, $text)) {
return;
}
throw new \Exception(sprintf('Did not find the subject "%s" in the mail', $text));

throw new \Exception(sprintf('Did not find the subject "%s" in the mail, subject was "%s"', $text, $subject));
}

/**
Expand All @@ -166,31 +161,4 @@ protected function parseMailBody(string $mailBody): string
}
return $unescapedMail;
}

/**
* @param string $string
* @param bool $quotedPrintableDecodeFlag
* @return string
*/
static protected function quotedPrintableDecodeRespectingEquals(
string $string,
bool $quotedPrintableDecodeFlag = false
): string {
if ($quotedPrintableDecodeFlag) {
return quoted_printable_decode($string);
}

return quoted_printable_decode(str_replace('=', '=3D', $string));
}


/**
* @param string $string
* @param string $charset
* @return string
*/
static protected function mimeDecodeSubject(string $string, string $charset): string
{
return iconv_mime_decode($string, ICONV_MIME_DECODE_CONTINUE_ON_ERROR, $charset);
}
}

0 comments on commit 8ca831d

Please sign in to comment.