Problem/Motivation

After we've implemented 'Reply-To' field in #2824195: Add "Reply-to" field next to the "From" field, we are still missing a check to proof if 'Reply-To' address is identical to 'From' address. In this case, the 'Reply-To' field should not be displayed. Also this case is not covered by our collection of email examples.

Proposed resolution

Do not display 'Reply-To' if it is identical to 'From'.
Add test coverage using plain-text-reply-to.eml replacing the two 'Reply-To' mailboxes with the same 'From' address.

Remaining tasks

User interface changes

API changes

Data model changes

Problem/Motivation

Proposed resolution

Remaining tasks

User interface changes

Before the fix, 'Reply-To' is displayed when it is the same as 'From':

After the fix, 'Reply-To' is NOT displayed when it is the same as 'From':

API changes

Data model changes

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

tduong created an issue. See original summary.

tduong’s picture

Here the patch, probably the template filename is too long.

IS updated with screenshots.

The last submitted patch, 2: do_not_display_ReplyTo-2826672-2-test_only.patch, failed testing.

miro_dietiker’s picture

Status: Needs review » Needs work
+++ b/inmail.module
@@ -430,14 +430,20 @@ function inmail_preprocess_inmail_message(&$variables) {
+      if (isset($from) && ($address['address'] == $from['address'])) {
+        continue;

If it is multiple, we should always list them all. We only want to have it removed if it is single and identical to from.

toncic’s picture

Assigned: tduong » toncic
Status: Needs work » Needs review
FileSize
4.53 KB
2.88 KB

Changed logic to show the reply-to if there are multiple addresses.

miro_dietiker’s picture

Status: Needs review » Needs work

Need work since we have the Rfc2822Address now.

+++ b/inmail.module
@@ -430,19 +430,32 @@ function inmail_preprocess_inmail_message(&$variables) {
+    if (count($reply_to) > 1) {
...
+      if (isset($from) && ($reply_to[0]['address'] !== $from['address'])) {

I would prefer to always do the foreach loop and later do the check:
if (count($reply_to)==1 && $reply_to[0]['address'] == $from['address'])..

And then unset the element.

toncic’s picture

Status: Needs work » Needs review
FileSize
4.1 KB
1.74 KB

Implement comm #6.

mbovan’s picture

Status: Needs review » Needs work
  1. +++ b/inmail.module
    @@ -430,14 +430,20 @@ function inmail_preprocess_inmail_message(&$variables) {
    +  $from = $message->getFrom();
    +  if ($from) {
    +    $variables['address_from'] = [
    +      '#type' => 'inmail_message_address',
    +      '#address' => $from,
    +    ];
    +  }
    

    I think we will always have "From" header in a message. Otherwise, the email message is invalid.

  2. +++ b/inmail.module
    @@ -430,14 +430,20 @@ function inmail_preprocess_inmail_message(&$variables) {
         foreach ($reply_to as $key => $address) {
    

    $key seems not needed.

  3. +++ b/inmail.module
    @@ -430,14 +430,20 @@ function inmail_preprocess_inmail_message(&$variables) {
    +      if (count($reply_to) == 1 && $address->getAddress() === $from->getAddress()) {
    +        return;
    +      }
    

    We should not use early return here. That means, no other preprocess code will be executed. Let's add a test to assert it.

    Also, we should compare email addresses rather than objects. That prevents the case of different names but same email addresses.

  4. +++ b/inmail.module
    index ea771b7..49e2971 100644
    --- a/src/Tests/InmailIntegrationTest.php
    
    --- a/src/Tests/InmailIntegrationTest.php
    +++ b/src/Tests/InmailIntegrationTest.php
    

    IMO, we should put these tests in the related mail element test - InmailMessageWebTest.

  5. +++ b/src/Tests/InmailIntegrationTest.php
    index 0000000..6350cb9
    --- /dev/null
    
    --- /dev/null
    +++ b/tests/modules/inmail_test/eml/plain-text-reply-to-multiple.eml
    
    +++ b/tests/modules/inmail_test/eml/plain-text-reply-to-multiple.eml
    index 0000000..3481ea7
    --- /dev/null
    
    --- /dev/null
    +++ b/tests/modules/inmail_test/eml/plain-text-reply-to-same-as-from.eml
    

    We have /addresses folder now. What about moving the emails in there?

  6. +++ b/tests/modules/inmail_test/eml/plain-text-reply-to-multiple.eml
    @@ -0,0 +1,15 @@
    +Received: from yahoo.mail.com; Fri, 21 Oct 2016 15:38:40 +0200 (CEST)
    
    +++ b/tests/modules/inmail_test/eml/plain-text-reply-to-same-as-from.eml
    @@ -0,0 +1,15 @@
    +Received: from yahoo.mail.com; Fri, 21 Oct 2016 15:38:40 +0200 (CEST)
    

    example.com

  7. +++ b/tests/modules/inmail_test/eml/plain-text-reply-to-multiple.eml
    @@ -0,0 +1,15 @@
    +Hi Alice!
    +
    +Congratulation on your passionate work and contribution to poetry.
    +Your works inspires many many people wide world.
    +
    +Sincerely,
    +Bob aka still Bob
    
    +++ b/tests/modules/inmail_test/eml/plain-text-reply-to-same-as-from.eml
    @@ -0,0 +1,15 @@
    +Hi Alice!
    +
    +Congratulation on your passionate work and contribution to poetry.
    +Your works inspires many many people wide world.
    +
    +Sincerely,
    +Bob aka still Bob
    

    Optional: it would be nice to have self-explanatory mail body, mentioning that it contains multiple reply-to addresses etc...

mbovan’s picture

+++ b/inmail.module
@@ -430,14 +430,20 @@ function inmail_preprocess_inmail_message(&$variables) {
+      if (count($reply_to) == 1 && $address->getAddress() === $from->getAddress()) {

Unrelated: $address->getAddress() is pretty confusing.
As a followup we could think about renaming Drupal\inmail\MIME\Rfc2822Address::getAddress() to getEmail() as it's always an email and more intuitive IMHO.

toncic’s picture

Implemented comm #8. I added in preprocess function break instead of return, break will only finish foreach.
Created follow-up for renaming getAddress().

  • miro_dietiker committed 84b1988 on 8.x-1.x authored by toncic
    Issue #2826672 by toncic, tduong, miro_dietiker: Do not display 'Reply-...
miro_dietiker’s picture

Status: Needs review » Fixed

Committed with comment refinements and now additionally preserving all keys in the preprocess.

  • miro_dietiker committed 672b6fd on 8.x-1.x authored by toncic
    Issue #2826672 by toncic, tduong, miro_dietiker: Do not display 'Reply-...
tduong’s picture

Just a question: In plain-text-reply-to-multiple.eml the first Reply-To mailbox is the same as From and the second Reply-To mailbox same as To.
What is the goal of this, is it made on purpose ?

tduong’s picture

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.