r3c / custom_from

Plugin for Roundcube webmail, enable virtual email sender input.
https://plugins.roundcube.net/#/packages/r3c/custom-from
Other
20 stars 14 forks source link

Wrong From field substitution #2

Closed jazzl0ver closed 11 years ago

jazzl0ver commented 11 years ago

In custom_from.php, at line 56: // Decode recipients from e-mail headers $targets = array_merge ( isset ($headers->from) ? $IMAP->decode_address_list ($headers->from) : array (), isset ($headers->cc) ? $IMAP->decode_address_list ($headers->cc) : array (), isset ($headers->cci) ? $IMAP->decode_address_list ($headers->cci) : array (), isset ($headers->to) ? $IMAP->decode_address_list ($headers->to) : array () );

I think the array $targets should not contain $headers->from, since it's not a target, it's a sender's address. Second, I'd put $headers->to as a 1st element of $targets array, since in most cases the recipient is listed in To: field.

So, the final variant: $targets = array_merge ( isset ($headers->to) ? $IMAP->decode_address_list ($headers->to) : array (), isset ($headers->cc) ? $IMAP->decode_address_list ($headers->cc) : array (), isset ($headers->cci) ? $IMAP->decode_address_list ($headers->cci) : array () );

Hope, you would agree with me and make a new release soon. Thanks!

r3c commented 11 years ago

Hi jazzl0ver,

elements from $headers->from are used to select correct identity when replying to your own mails, however you're right about $headers->to being misplaced. I just pushed a fix, feel free to create a pull request if you have a better solution.

Regards, Rémi

jazzl0ver commented 11 years ago

Hi Remi.

Looks like there's a mistake in the algorithm when you try to reply to yourself. I think there should be a check if the from address is yours before filling $targets. And if this is a case, don't do the substitution at all.

It may look like this (line 51): if ($headers !== null && isset ($headers->to) && !in_array($headers->from, $my_identities)) { ...

r3c commented 11 years ago

E-mail sender (headers->from) cannot be matched against my_identities as it could be a virtual identity you created for this specific mail only. There's no way to be sure an e-mail has been sent by or to you, that's why I'm trying to find the best match in both sender and recipients adresses.