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

Detect message type, text or html #582

Open
Spl4x opened this issue Oct 28, 2024 · 3 comments
Open

Detect message type, text or html #582

Spl4x opened this issue Oct 28, 2024 · 3 comments

Comments

@Spl4x
Copy link

Spl4x commented Oct 28, 2024

Friends

Is there any function or method to detect if a message is HTML or TEXT?

For example:

if(condition){
	$body = $message->getBodyHtml();
} else {
	$body = $message->getBodyText();
}

Or the possibility of retrieving the complete message regardless of the type with a single function.

It happens to me that a message, for example, a response to a server error (Delivery Status Notification (Failure)) comes with the first part in text and the second part in html. When I retrieve the message through the library, it only detects part of the content.

Thanks!

@Slamdunk
Copy link
Collaborator

Retrieve both bodies and check which one isn't null?

@Spl4x
Copy link
Author

Spl4x commented Oct 29, 2024

@Slamdunk

In most cases both functions return a valid value.

It would be ideal for the getBodyHtml() function to return null if it is not HTML, if so you could use:

$body = $message->getBodyHtml() ?? $message->getBodyText();

But this is not the case, both getBodyHtml() and getBodyText() return the formatted message.

I have cases where, for example, messages arrive in text, but they have an EML file attached with the HTML message. The ddeboer library attaches this attachment as if it were part of the received message.

@Spl4x
Copy link
Author

Spl4x commented Oct 30, 2024

In another library (php-imap) they have 2 functions that solve this problem:

Check if a text body exists
$status = $message->hasTextBody();

Check if an html body exists
$status = $message->hasHTMLBody();

Source: https://www.php-imap.com/api/message

Additionally, it has a very interesting function, which allows you to add embedded images to messages:
$body = $message->mask()->getHTMLBodyWithEmbeddedBase64Images();

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

No branches or pull requests

2 participants