Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mail notification for new share generates invalid email from (Error: Swift_RfcComplianceException: Address in mailbox given [...] does not comply with RFC 2822, 3.6.2.) #26683

Closed
0x47 opened this issue Apr 21, 2021 · 6 comments · Fixed by #27199
Labels
1. to develop Accepted and waiting to be taken care of bug feature: emails feature: sharing
Milestone

Comments

@0x47
Copy link

0x47 commented Apr 21, 2021

The code at:

$message->setFrom([\OCP\Util::getDefaultEmailAddress($instanceName) => $senderName]);
creates invalid e-mail from addresses if the server is not configured to use fixed custom mail_from_address. Error messages are:

Error: Swift_RfcComplianceException: Address in mailbox given [...] does not comply with RFC 2822, 3.6.2.

As can be seen in

$user_part = $config->getSystemValue('mail_from_address', $user_part);
the parameter $user_part is used if mail_from_address has not been set for the instance. The instanceName given by the sendMailNotification function may contain spaces which is not allowed.
$instanceName = $this->defaults->getName();

Please use a $user_part similar to the lost password function:

return Util::getDefaultEmailAddress('lostpassword-noreply');
Here, the $user_part makes sense and is not dependent on arbitrary strings defined in the admin section. Maybe use something like shares-noreply.

@solracsf solracsf changed the title Mail notification for new share generates invalid email from (Error: Swift_RfcComplianceException: Address in mailbox given [...] does not comply with RFC 2822, 3.6.2.) Mail notification for new share generates invalid email from (Error: Swift_RfcComplianceException: Address in mailbox given [...] does not comply with RFC 2822, 3.6.2.) Apr 22, 2021
@szaimen szaimen added the 0. Needs triage Pending check for reproducibility or if it fits our roadmap label May 20, 2021
@MorrisJobke MorrisJobke added 1. to develop Accepted and waiting to be taken care of bug feature: emails feature: sharing and removed 0. Needs triage Pending check for reproducibility or if it fits our roadmap labels May 27, 2021
@MorrisJobke MorrisJobke added this to the Nextcloud 22 milestone May 27, 2021
@MorrisJobke
Copy link
Member

MorrisJobke commented May 27, 2021

I noticed this on a setup where no email is configured and it took Powered by Company@localhost.localdomain as sender. Setup check was green. Maybe it should also warn about a missing mail setup in there.

cc @kesselb

@MorrisJobke
Copy link
Member

The response to the POST request to /shares was:

{
    "ocs": {
        "meta": {
            "status": "faulure",
            "statuscode": 403,
            "message": "Address in mailbox given [Powered by Company@localhost.localdomain| does not comply with RFC 2822, 3.6.2."
        }
    }
}

That email username is coming most likely from the theming as #21120 (comment)

@MorrisJobke
Copy link
Member

cc @juliushaertl for the theming part

@0x47
Copy link
Author

0x47 commented May 27, 2021

Setup check was green. Maybe it should also warn about a missing mail setup in there.

In my opinion the issue is not a missing mail setup but simply a bug in the code. Why would you ever use $instanceName as the sender of a mail? It can be an arbitrary string with spaces in it.

Having no sender part in the server mail configuration is a perfectly fine use case. It should (and will in at least two cases) use specific sender parts (noreply@... and lostpassword-noreply@...) for each purpose.

EDIT: Just to clarify, $instanceName is filled with $this->defaults->getName() as described in the first comment, check

$instanceName = $this->defaults->getName();

@MorrisJobke
Copy link
Member

In my opinion the issue is not a missing mail setup but simply a bug in the code. Why would you ever use $instanceName as the sender of a mail? It can be an arbitrary string with spaces in it.

True point. 👍 That should be fixed.

MorrisJobke added a commit that referenced this issue May 28, 2021
Fixes #26683

Before it used the instance name, which a) doesn't make sense to randomly guess email addresses and b) could contain characters that are not allowed in email addresses like spaces.

Signed-off-by: Morris Jobke <hey@morrisjobke.de>
@MorrisJobke
Copy link
Member

Fix is in #27199

backportbot-nextcloud bot pushed a commit that referenced this issue May 28, 2021
Fixes #26683

Before it used the instance name, which a) doesn't make sense to randomly guess email addresses and b) could contain characters that are not allowed in email addresses like spaces.

Signed-off-by: Morris Jobke <hey@morrisjobke.de>
backportbot-nextcloud bot pushed a commit that referenced this issue May 28, 2021
Fixes #26683

Before it used the instance name, which a) doesn't make sense to randomly guess email addresses and b) could contain characters that are not allowed in email addresses like spaces.

Signed-off-by: Morris Jobke <hey@morrisjobke.de>
backportbot-nextcloud bot pushed a commit that referenced this issue May 28, 2021
Fixes #26683

Before it used the instance name, which a) doesn't make sense to randomly guess email addresses and b) could contain characters that are not allowed in email addresses like spaces.

Signed-off-by: Morris Jobke <hey@morrisjobke.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1. to develop Accepted and waiting to be taken care of bug feature: emails feature: sharing
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants