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

Laminas mail expects a value in the format "type/subtype"; received "image/*" #119

Open
lfardin opened this issue Dec 18, 2020 · 19 comments · May be fixed by #264
Open

Laminas mail expects a value in the format "type/subtype"; received "image/*" #119

lfardin opened this issue Dec 18, 2020 · 19 comments · May be fixed by #264
Labels
Bug Something isn't working

Comments

@lfardin
Copy link

lfardin commented Dec 18, 2020

Issue detected when using GLPI Mailgate glpi-project/glpi#8375 to get messages with attached files "image/*"

To fix this issue, the RegEx at the file "laminas-mail/src/Header/ContentType.php", line 114 should be changed to

/^[a-z-]+/[/*a-z0-9.+-]+$/i

@lfardin lfardin added the Bug Something isn't working label Dec 18, 2020
@warmech777
Copy link

Hi
When I change RexEx in line 114 to /^[a-z-]+/[/*a-z0-9.+-]+$/i I start receiving new error messages
Laminas\Mail\Header\ContentType::setType expects a value in the format "type/subtype"; received "multipart/mixed"

How to fix it...?

@glensc
Copy link
Contributor

glensc commented Dec 23, 2020

It's rather unclear what are you even trying to do, what is the problem in question.

@warmech777
Copy link

It's rather unclear what are you even trying to do, what is the problem in question.

Sorry. I will try to add full details.
From the start I have problems when GLPI trying to receive some mails with images in attach. This look like "Laminas\Mail\Header\ContentType::setType expects a value in the format "type/subtype"; received "image/*"" message in logs. To fix this issue, the RegEx at the file "laminas-mail/src/Header/ContentType.php", line 114 changed to /^[a-z-]+/[/*a-z0-9.+-]+$/i . This does not help. GLPI stop receiving any mails and I see new error messages in log "Laminas\Mail\Header\ContentType::setType expects a value in the format "type/subtype"; received "multipart/mixed""

@glensc
Copy link
Contributor

glensc commented Dec 23, 2020

Looks like The XY Problem, you think the problem is about regex, but not described the actual problem. you need to make a reproducible scenario for a library like laminas-mail, with describing clearly what are the expectation.

you can upload the reproducer as https://gist.github.com/ or (i think) attach a .zip file to issue tracker works too. the reproducer should be standalone and minimal to show clearly the problem. include copy of the email in question.

@mrjd19811
Copy link

Could this be causing a strange side effect of our incoming email tickets being given prior ticket numbers?

@mrjd19811
Copy link

Tried the adjustment above, having same effect as warmech777

There is def something wrong in here and I think it caused my prior issues, I'm going to go look at this files history.

@mrjd19811
Copy link

I essentially just commented out 114-120, and it seems to have resolved my problems. I'll keep an eye on this thread for the proper fix.
image

@mrjd19811
Copy link

Well, this got rid of the errors in mailgate, but still having my issue of new tickets occasionally assigning to old ticket ID's. Looking else where.

@rikvdh
Copy link

rikvdh commented Feb 13, 2021

Ok, I'm bumping this issue since I've got the same situation while reading messages. It appears that 'Samsung Email on Android' generates an 'image/*' content-type for images.

Here is a link to the gist: https://gist.github.com/rikvdh/489e13b22f9012db2dcd9f5046b53e43
I think changing the regex would be the way to go as a workaround for this issue. In the end, it is an issue in the mail-client of the user.

@FredVH
Copy link

FredVH commented Sep 15, 2021

The regex should be

/^[a-z-]+\/[\*a-z0-9.+-]+$/i

instead of

/^[a-z-]+\/[/*a-z0-9.+-]+$/i

as suggested on glpi-project/glpi#8375 (comment)

@tomolimo
Copy link

Hello,
I also came to this issue with an email sent from a smartphone...
And the issue has been fixed using the following regex: /^[a-z-]+/[*a-z0-9.+-]+$/i
Thank you,
Regards,
Tomolimo

@tomolimo tomolimo linked a pull request May 31, 2024 that will close this issue
@Xerkus
Copy link
Member

Xerkus commented May 31, 2024

Technically, this is a not a valid content type. RFC 2045 allows either IANA registered type or private subtype prefixed with x-. Considering that it is neither and it is not even a real content type that did not bother to go through registration procedure, content type image/* is a BUG in composing software.

However, as per RFC 2045 image/x-* is a valid content type:

https://datatracker.ietf.org/doc/html/rfc2045#section-5.1

 token := 1*<any (US-ASCII) CHAR except SPACE, CTLs,
             or tspecials>

 tspecials :=  "(" / ")" / "<" / ">" / "@" /
               "," / ";" / ":" / "\" / <">
               "/" / "[" / "]" / "?" / "="
               ; Must be in quoted-string,
               ; to use within parameter values

Overall, image/* makes no sense but should be allowed for the purposes of this library.

@tomolimo
Copy link

Hello @Xerkus
Yes I totally agree with you, but we have no choice, we cannot loose incoming emails sent from smartphones (for example) even if they do not respect 100% the RFC.
Thank you
Regards,
Tomolimo

@Xerkus
Copy link
Member

Xerkus commented May 31, 2024

This library is used for composing emails and it does not make a distinction between parsed non-conforming email and composed non-conforming email. Invalid composed emails can not be allowed. For this reason rejecting invalid email is preferable.

@tomolimo
Copy link

Could it be then that an additional (optional) parameter can be used to inform the method that we are in the process of analyzing received emails, in order to differentiate composition or reception?

@rikvdh
Copy link

rikvdh commented May 31, 2024

@Xerkus Not only composing emails. Together with IMAP/POP this is also used for reading in emails from external clients, which can be anything. ofc it is not according RFC. But don't get me started on mails not conforming RFC.

@tomolimo See #146

@tomolimo
Copy link

Hello @rikvdh
We had in the past exactely the same issues as mentioned in #146 and I made a small modification in the source code to enable non-strict validation of domains in email addresses...
thank you
Regards,
Tomolimo

@rikvdh
Copy link

rikvdh commented May 31, 2024

I'm currently maintaining a fork with a lot of those exceptions commented out. I would like to think of something which could become mainline (like a function to turn those exceptions off). But this is quite convoluted when in your application message-decoding is 'abstracted' behind an 'imap-client' and some checks are deeper in other repo's.

https://github.com/rikvdh/laminas-mail/tree/v2.25-non-strict

@tomolimo
Copy link

This is the same case for us, we are using GLPI (= ITSM), which in turns is using laminas-mail for the emails input, see glpi-project/glpi#8375

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants