Skip to content

Number of attachments change on each message read #418

@kolonuk

Description

@kolonuk

Describe the bug
Using a "simple" program to access Office365 account with a single email, everytime I check the number of attachments, it changes.

The example email has three attachments, an inline image, and two attachments, a text document and another image. The program reports the attachments as 2 or 3 randomly.

What is interesting is that the missing attachment is always the first "attachment" which is the image, the inline image and text file attachment are always picked up.

Used config
Default, as per release. dispositions' => ['attachment', 'inline'],

Code to Reproduce (Fill in the missing details for your own environment)

<?php
error_reporting(E_ALL);
ini_set('display_errors','1');
ini_set('display_startup_errors', 1);

use Webklex\PHPIMAP\ClientManager;
include __DIR__.'/php-imap-4.1.2/vendor/autoload.php'; 
$optionsfile="php-imap-4.1.2/src/config/imap.php";

// OAuth2 variables
$CLIENT_ID = "";
$CLIENT_SECRET = "";
$TENANT = "";
$SCOPE = "https://outlook.office365.com/IMAP.AccessAsUser.All";

$REDIRECT_URI = "http://localhost/test_imap";
$CODE="";
$SESSION="";
$ACCESS_TOKEN = "";

$url= "https://login.microsoftonline.com/$TENANT/oauth2/v2.0/token";
$O365Username = "";

$param_post_curl = [ 
	'client_id'=>$CLIENT_ID,
	'client_secret'=>$CLIENT_SECRET,
	'refresh_token'=>$REFRESH_TOKEN,
	'grant_type'=>'refresh_token' ];
   
$ch=curl_init();
  
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POSTFIELDS, http_build_query($param_post_curl));
curl_setopt($ch,CURLOPT_POST, 1);
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, false);
 
$oResult=curl_exec($ch);
$json=json_decode($oResult);
$ACCESS_TOKEN=$json->access_token;
$REFRESH_TOKEN=$json->refresh_token;

$cm = new ClientManager($optionsfile);
$client = $cm->make([
    'host'          => 'outlook.office365.com',                
    'port'          => "993",
    'encryption'    => 'ssl',
    'validate_cert' => true,
    'username'      => $O365Username,
    'password'      => $ACCESS_TOKEN,
    'protocol'      => 'imap',
    'authentication' => "oauth"
]);

$client->connect();
$folder = $client->getFolder('INBOX');
$messages = $folder->messages()->all()->get();
$info = $folder->examine();
$total = $info['exists'];
echo "Messages waiting to be processed: ".$total."\n";

foreach($messages as $message){
    echo "Number attachments:".$message->getAttachments()->count()."\n";
    
    $rawmsg=$message->getRawBody();
	$y=substr_count($rawmsg,"Content-Disposition: attachment")+substr_count($rawmsg,"Content-Disposition: inline");
	echo "body attachments:".$y."\n";
}

Expected behavior
The same number of attachments every time the message is processed.

Screenshots
image

Desktop / Server (please complete the following information):

  • OS: Debian 10, up to date
  • PHP: 7.3.31-1~deb10u3
  • Version: 4.1.2 <- I understand that this is an old version, but I only have access to PHP7.3
  • Provider: Outlook

Additional context
The initial email was sent from an Outlook client, passed through an exim filter, then out to Exchange online.

I can supply the envelope and raw body if required.

I can temporarily provide connection strings for testing purposes, and/or forward the msg as attachment.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions