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

getTextBody() is null and the email text is treated as attachment #320

Closed
nettunodev opened this issue Nov 8, 2022 · 2 comments
Closed

Comments

@nettunodev
Copy link

nettunodev commented Nov 8, 2022

Hello,
calling $message->getTextBody() always outputs null. Instead I find the plain text in the attachment, treated as an inline text attachment.

My configuration

	$cm = new ClientManager();
	
	$client = $cm->make([
	   'host'           => 'outlook.office365.com',
	   'port'           => 993,
	   'protocol'       => 'imap',
	   'encryption'     => 'ssl',
	   'validate_cert'  => false,
	   'username'       => [redacted],
	   'password'       => [redacted oauth2 token],
	   'authentication' => 'oauth',
	   'sequence'		=> 'IMAP::ST_UID',
	   'dispositions'	=> ['attachment', 'inline'], **(but I also tried ['attachment'] and also omitting this entirely)**
	   'fetch'			=> 'IMAP::FT_PEEK'',
	   'fetch_order'	=> 'desc'
	]);		

My code

	$folder = $client->getFolder('INBOX');
	$query = $folder->query();
	$message = $query->getMessageByUid($id);

	$textPlain = $message->getTextBody(); // returns null

Then I try to download the attachment

foreach($allAttachments as $attachment){
		
	print_r($attachment->getAttributes()); 

I get this

Array
(
    [content] => [redacted, here I find the plain text of the email]
    [type] => text
    [part_number] => 0
    [content_type] => text/plain
    [id] => 
    [name] => undefined
    [disposition] => Webklex\PHPIMAP\Attribute Object
        (
            [name:protected] => content_disposition
            [values:protected] => Array
                (
                    [0] => inline
                )

        )

    [img_src] => 
    [size] => 1479
)

I expected to get the email plain text. This happens every time I try to get the plain text of an email.

  • OS: Ubuntu 16.04
  • PHP: 7.1.8
  • Version: 4.4.0
  • Provider: Outlook but I also tried other provider. It happens to every certified email from the Aruba PEC provider.

I'm attaching two emails that have the same issue.

Edit:

I found out that if I change the default options in the imap.php file in the config directory, from
'dispositions' => ['attachment', 'inline'],
to
'dispositions' => ['attachment'],
it does work.
Shouldn't the configuration in the make method overwrite the standard configuration? Also, what would happen if someone would attach an inline image? Shouldn't the email text be treated as what it is, the plain text of the email and not an attachment?

Thanks!

mail1.txt
mail2.txt

@freescout-helpdesk
Copy link
Contributor

Exactly same issue here. What is the right way to deal with this?

Should we always change 'dispositions' => ['attachment', 'inline'] to 'dispositions' => ['attachment']? Will it have any sideffects?

@Webklex
Copy link
Owner

Webklex commented Mar 16, 2023

Hi @nettunodev ,
many thanks for your report. Please update to v5.1 and give it another try.
If you are currently using an older version below v5.0, please read the breaking changes leading up to v5.1 before upgrading.

Best regards,

@Webklex Webklex closed this as completed Jun 23, 2023
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

No branches or pull requests

3 participants