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

MailBuilder.Build() requires non-empty subject #160

Closed
zeldrinn opened this issue Jul 16, 2020 · 5 comments · Fixed by #191
Closed

MailBuilder.Build() requires non-empty subject #160

zeldrinn opened this issue Jul 16, 2020 · 5 comments · Fixed by #191

Comments

@zeldrinn
Copy link

What I did: Tried to call MailBuilder.Build() on a MailBuilder with an empty string for the subject field.

msg := enmime.Builder().
	From("[email protected]", "[email protected]").
	Subject("")

rootPart, err := msg.Build()
if err != nil {
	return nil, err
}

What I expected: I expected to be able to build an email object with an empty subject, as plenty of real world emails have empty subjects.

What I got: Received error subject not set (https://github.com/jhillyerd/enmime/blob/v0.6.0/builder.go#L220)

Release or branch I am using: v0.6.0

It's not clear to me why the validation logic in Build() would require subject to be non-empty.

@jhillyerd
Copy link
Owner

The goal of the builder was to help people create well formed emails. While an email without a subject is valid, it is not well formed in my opinion.

Is there a use case that would help me understand why you want to do this?

@zeldrinn
Copy link
Author

zeldrinn commented Jul 28, 2020

@jhillyerd Thanks for the quick reply!

Not sure what the distinction is between "valid" and "well formed"...

The use case I ran into is needing to reconstruct an Office 365 (Outlook) envelope. When I do this for Gmail, I can simply call enmime.ReadEnvelope(bytes.NewReader(emailRaw)) on the raw email bytes (which is provided by the Gmail API), but I don't believe the Office 365 API provides the raw byte representation of an email. So in order to construct an envelope I'm using Build() to create it from scratch, using the body, subject and some of the headers, etc. As my service is ingesting emails from real inboxes, it's inevitable that some of these emails have empty subjects.

It seems reasonable that you'd be able to use Build() to construct any syntactically valid email object, rather than having it impose checks that I'd argue fall into the realm of "style".

@jhillyerd
Copy link
Owner

The builder has many other "style" limitations you may not be aware of, so this is inline with its design philosophy.

Adding a Send() method to Envelope (see also #158) would probably be a better approach to allowing generation of more specialized emails.

@psanford
Copy link
Contributor

I've run into this trying to do a similar thing as @zeldrinn . Perhaps builder could have a flag to make this check optional for folks who know they do in fact want to send an email with an empty subject line.

@jhillyerd
Copy link
Owner

Given this use case is more common than I expected, I think we can just remove the subject check.

jhillyerd pushed a commit that referenced this issue Apr 25, 2021
This is valid for email systems and sometimes necessary, especially
when you don't have direct control over the souce input.

Fixes #160
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants