imap icon indicating copy to clipboard operation
imap copied to clipboard

Parsing message body content issues

Open Gr33nLight opened this issue 6 years ago • 1 comments

Hello, We have configured the module to connect to our mailbox server. Below is the code we use to connect:

use Ddeboer\Imap\Server;

$flags = '/imap/notls/novalidate-cert';
$server = new Server('url','143',$flags);
$connection = $server->authenticate('here the username', 'here the password');

$mailboxes = $connection->getMailboxes();
$c=0;

foreach ($mailboxes as $mailbox) {
	$messages = $mailbox->getMessages();

	foreach ($messages as $message) {
    	// $message is instance of \Ddeboer\Imap\Message
  		echo "FROM: ".$message->getFrom()->getAddress()."<br>";
  		if($message->getContent()!='') echo "<pre>GETCONTENT: ".$message->getContent()."</pre>";
  		if($message->getBodyText()!='') echo "<pre>TEXT: ".$message->getBodyText();
  		if($message->getBodyHtml()!='') echo "<pre>HTML: ".$message->getBodyHtml();
  		
	}
}

The problem we found is this: Calling the function $message->getContent() seems to determine the output of the function $message->getBodyText(). Example, if we call the $message->getContent() first, then the function getBodyText will return the correct string. If we call getBodyText before getContent then, the function getBodyText will return empty and the fuction getContent will return sometimes a base64 encoded string containing the body of the email. Have you encountered this issue before? And if so could you suggest a fix around it? Thanks

Gr33nLight avatar Jan 21 '19 11:01 Gr33nLight

Does this issue still exist? @Gr33nLight

OskarStark avatar Jan 24 '20 12:01 OskarStark