Closed kasperfd closed 4 years ago
Hi @kasperfd, thanks for your well formatted issue.
The described bug seems to be realy odd. I assume just like you did that it's probably a client related issue.
However your mail headers look fine to me. The only thing that caught my attention was the Groupwise flag.
From https://books.google.de/books?id=D3Om_zmjW7oC&pg=PT94&lpg=PT94&dq=Groupwise+empty+mail+body
[..] Forward as Attachment leaves the new message's body blank and places the forwarded message as an attachment.
Please check the mail attachment of these specific "empty" mails. If your body is indeed an attachment please provide some additional information:
var_dump([
'mime_type' => $attachment->getMimeType(),
'type' => $attachment->getType(),
'name' => $attachment->getName(),
'disposition' => $attachment->getDisposition(),
'content_type' => $attachment->getContentType(),
]);
Btw the client you used to "resend" the mail might detect the attachment as some sort of body-part and use them as mail body automatically(?).
At this point this is just a vague guess. Please keep me updated on how things worked out :)
Best regards
Thanks for your quick response - this is very helpful.
The "Groupwise" pointed me in some direction to google on. Your assumption about the body treated as attachment might be correct - see following two temp file attachments:
Office 365 can preview the email body correctly when viewing it so somehow it should be possible hm :)
I didn't managed to print out any attachments in the code though - just empty unfurtunately. I even looked at the $message object again without luck seeing anything helpful.
Do you have other suggestions ? :) I've asked the client to sent a clean test email to me and then I can show you a full var_dump / print of the $message object (perhaps you can see something making sense)
@Webklex : Ok I got a little further.
Maybe you can spot something I could change in the "Message.php" so it might work ? :)
I just did following in Message.php and got some readable body text out even though these two lines are empty:
$body = $message->getTextBody();
$body = $message->getHTMLBody($this->replaceImageWithLinks);
So somewhere following should give us a clue and improve this to be working (hopefully):
private function fetchStructure($structure, $partNumber = null) {
\Log::info('--------- fetchStructure---------');
\Log::info('partNumber: ' . $partNumber);
\Log::info(print_r($structure, true));
$encoding = $this->getEncoding($structure);
$test = imap_fetchbody($this->client->getConnection(), $this->uid, $partNumber, $this->fetch_options | IMAP::FT_UID);
$test = $this->decodeString($test, $structure->encoding);
if ($encoding != 'us-ascii') {
$test = $this->convertEncoding($test, $encoding);
}
\Log::info(print_r($test, true));
And the result:
[2019-04-04 11:57:20] local.INFO: --------- fetchStructure---------
[2019-04-04 11:57:20] local.INFO: partNumber: 1
[2019-04-04 11:57:20] local.INFO: stdClass Object
(
[type] => 0
[encoding] => 3
[ifsubtype] => 1
[subtype] => PLAIN
[ifdescription] => 0
[ifid] => 0
[lines] => 4
[bytes] => 376
[ifdisposition] => 1
[disposition] => inline
[ifdparameters] => 1
[dparameters] => Array
(
[0] => stdClass Object
(
[attribute] => modification-date
[value] => Thu, 3 Apr 2019 15:50:39 +0100
)
)
[ifparameters] => 1
[parameters] => Array
(
[0] => stdClass Object
(
[attribute] => charset
[value] => utf-8
)
)
)
[2019-04-04 11:57:20] local.INFO: Hi Kasper
This is a test email......
Regards
[2019-04-04 11:57:20] local.INFO: --------- fetchStructure---------
[2019-04-04 11:57:20] local.INFO: partNumber: 2.1
[2019-04-04 11:57:20] local.INFO: stdClass Object
(
[type] => 0
[encoding] => 3
[ifsubtype] => 1
[subtype] => HTML
[ifdescription] => 0
[ifid] => 0
[lines] => 52
[bytes] => 4044
[ifdisposition] => 1
[disposition] => inline
[ifdparameters] => 1
[dparameters] => Array
(
[0] => stdClass Object
(
[attribute] => modification-date
[value] => Thu, 3 Apr 2019 15:50:39 +0100
)
)
[ifparameters] => 1
[parameters] => Array
(
[0] => stdClass Object
(
[attribute] => charset
[value] => utf-8
)
)
)
[2019-04-04 11:57:20] local.INFO: <html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="GENERATOR" content="MSHTML 11.00.10570.1001"></head>
<body style="FONT: 10pt Segoe UI; MARGIN: 4px 4px 1px">
<div>Hi Kasper</div>
<div>This is a test email......</div>
<div> </div>
<div>Regards</div>
<div> </div>
</body></html>
[2019-04-04 11:57:20] local.WARNING: The email body is empty for following subject: Test email
have the same problem
Both $message->getTextBody() and $message->getHTMLBody() come empty.
Hi @kasperfd , please go ahead and give the current master version a try.
@emtudo thanks for your pull requests! :)
Best regards
Hi @Webklex ,
Great - just tried the latest version but still empty unfurtunately :/
Could you track something from the log above ?
Regards
Hi @kasperfd, The @Webklex did not generate a new tag, did you directly try the branch master?
@Webklex Could you release a new version tag?
Hi @emtudo , 1.4.1 is already released containing all latest commits :)
@kasperfd I'm having a hard time simulating this "feature" :/ The structure looks fine to me and should be fetched.
Could you check if Message::fetchStructure() L:696 gets reached and $body is actually filled? The same with L:717?
@Webklex Had not noticed, thank you!
@Webklex Sorry - Easter holidays came in the way :)
I checked Message:fetchStructure for both lines - they are never called for this test email.
They are not coming through this one:
if ($structure->type == IMAP::MESSAGE_TYPE_TEXT && ($structure->ifdisposition == 0 || ($structure->ifdisposition == 1 && !isset($structure->parts) && $partNumber == null) ) ) {
It seems ifdisposition is 1 and partNumber is not null and therefore it fails.
Here's my log printing out the important stuff before the if statement above so you can see the whole thing (info: there's an inline signature image s don't get confused :) )
[2019-04-23 19:29:37] local.INFO: --------- fetchStructure---------
[2019-04-23 19:29:37] local.INFO: $partNumber:
[2019-04-23 19:29:37] local.INFO: $structure->type: 1
[2019-04-23 19:29:37] local.INFO: $structure->subtype: ALTERNATIVE
[2019-04-23 19:29:37] local.INFO: $structure->ifdisposition: 0
[2019-04-23 19:29:37] local.INFO: $structure->parts: is set
[2019-04-23 19:29:37] local.INFO: $content2:
[2019-04-23 19:29:37] local.INFO: (headers)
--UZMFBFSJZICTFZLSLAKP Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: base64 Content-Disposition: inline; modification-date="Thu, 3 Apr 2019 15:50:39 +0100"
--UZMFBFSJZICTFZLSLAKP Content-Type: multipart/related; boundary="KJOVFHYGTXPIHXKOXBNQ"
--KJOVFHYGTXPIHXKOXBNQ Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: base64 Content-Disposition: inline; modification-date="Thu, 3 Apr 2019 15:50:39 +0100"
--KJOVFHYGTXPIHXKOXBNQ
Content-ID:
--KJOVFHYGTXPIHXKOXBNQ--
--UZMFBFSJZICTFZLSLAKP--
[2019-04-23 19:29:37] local.INFO: --------- fetchStructure---------
[2019-04-23 19:29:37] local.INFO: $partNumber: 1
[2019-04-23 19:29:37] local.INFO: $structure->type: 0
[2019-04-23 19:29:37] local.INFO: $structure->subtype: PLAIN
[2019-04-23 19:29:37] local.INFO: $structure->ifdisposition: 1
[2019-04-23 19:29:37] local.INFO: $structure->parts: is set
[2019-04-23 19:29:38] local.INFO: $content2:
[2019-04-23 19:29:38] local.INFO: Hi Kasper
This is a test email......
Regards
[2019-04-23 19:29:38] local.INFO: --------- fetchStructure---------
[2019-04-23 19:29:38] local.INFO: $partNumber: 2
[2019-04-23 19:29:38] local.INFO: $structure->type: 1
[2019-04-23 19:29:38] local.INFO: $structure->subtype: RELATED
[2019-04-23 19:29:38] local.INFO: $structure->ifdisposition: 0
[2019-04-23 19:29:38] local.INFO: $structure->parts: is set
[2019-04-23 19:29:38] local.INFO: $content2:
[2019-04-23 19:29:38] local.INFO: --KJOVFHYGTXPIHXKOXBNQ
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: base64
Content-Disposition: inline; modification-date="Thu, 3 Apr 2019 15:50:39
+0100"
--KJOVFHYGTXPIHXKOXBNQ
Content-ID:
--KJOVFHYGTXPIHXKOXBNQ--
[2019-04-23 19:29:38] local.INFO: --------- fetchStructure---------
[2019-04-23 19:29:38] local.INFO: $partNumber: 2.1
[2019-04-23 19:29:38] local.INFO: $structure->type: 0
[2019-04-23 19:29:38] local.INFO: $structure->subtype: HTML
[2019-04-23 19:29:38] local.INFO: $structure->ifdisposition: 1
[2019-04-23 19:29:38] local.INFO: $structure->parts: is set
[2019-04-23 19:29:38] local.INFO: $content2:
[2019-04-23 19:29:38] local.INFO:
I have the same issue, this is the output of $message->getStructure()
for the mail with the type 1 it returns empty body
{
"type": 1,
"encoding": 0,
"ifsubtype": 1,
"subtype": "ALTERNATIVE",
"ifdescription": 0,
"ifid": 0,
"ifdisposition": 0,
"ifdparameters": 0,
"ifparameters": 1,
"parameters": [
{
"attribute": "boundary",
"value": "=_E61F1356043B1EE99CACC3E901FA04CB"
}
],
"parts": [
{
"type": 0,
"encoding": 4,
"ifsubtype": 1,
"subtype": "PLAIN",
"ifdescription": 1,
"description": "plainpart",
"ifid": 0,
"lines": 202,
"bytes": 3160,
"ifdisposition": 1,
"disposition": "inline",
"ifdparameters": 0,
"ifparameters": 1,
"parameters": [
{
"attribute": "charset",
"value": "UTF-8"
}
]
},
{
"type": 0,
"encoding": 4,
"ifsubtype": 1,
"subtype": "HTML",
"ifdescription": 1,
"description": "htmlpart",
"ifid": 0,
"lines": 475,
"bytes": 24725,
"ifdisposition": 1,
"disposition": "inline",
"ifdparameters": 0,
"ifparameters": 1,
"parameters": [
{
"attribute": "charset",
"value": "UTF-8"
}
]
}
]
}
I have the same problem. Some system or mailclient sending mails with type "multipart". The problem is in the fetchStructure() method as the others said.
my mail subtypes: PLAIN and HTML in the "parts" array, and "ifdisposition" value is "1" in both part. Your condition in the beginning of fetchStructure method not able to process my subtypes. The consequence is my content (html and plain) is empty.
I tried forward this message to other mail accont, but the outlook convert it to text typed message. So i cant send this mail for you :(
I dont know that mails meets the standard, but many customers send me such mails so its a real problem.
I hope it helps to solve this issue.
my fetched structure object:
object(stdClass)#875 (11) {
["type"]=>
int(1)
["encoding"]=>
int(0)
["ifsubtype"]=>
int(1)
["subtype"]=>
string(11) "ALTERNATIVE"
["ifdescription"]=>
int(0)
["ifid"]=>
int(0)
["ifdisposition"]=>
int(0)
["ifdparameters"]=>
int(0)
["ifparameters"]=>
int(1)
["parameters"]=>
array(1) {
[0]=>
object(stdClass)#869 (2) {
["attribute"]=>
string(8) "boundary"
["value"]=>
string(29) "----------=_1561117803-7184-0"
}
}
["parts"]=>
array(2) {
[0]=>
object(stdClass)#867 (13) {
["type"]=>
int(0)
["encoding"]=>
int(4)
["ifsubtype"]=>
int(1)
["subtype"]=>
string(5) "PLAIN"
["ifdescription"]=>
int(0)
["ifid"]=>
int(0)
["lines"]=>
int(30)
["bytes"]=>
int(1233)
["ifdisposition"]=>
int(1)
["disposition"]=>
string(6) "inline"
["ifdparameters"]=>
int(0)
["ifparameters"]=>
int(1)
["parameters"]=>
array(1) {
[0]=>
object(stdClass)#866 (2) {
["attribute"]=>
string(7) "charset"
["value"]=>
string(5) "utf-8"
}
}
}
[1]=>
object(stdClass)#865 (13) {
["type"]=>
int(0)
["encoding"]=>
int(4)
["ifsubtype"]=>
int(1)
["subtype"]=>
string(4) "HTML"
["ifdescription"]=>
int(0)
["ifid"]=>
int(0)
["lines"]=>
int(24)
["bytes"]=>
int(1804)
["ifdisposition"]=>
int(1)
["disposition"]=>
string(6) "inline"
["ifdparameters"]=>
int(0)
["ifparameters"]=>
int(1)
["parameters"]=>
array(1) {
[0]=>
object(stdClass)#864 (2) {
["attribute"]=>
string(7) "charset"
["value"]=>
string(5) "utf-8"
}
}
}
}
}
@Webklex : what do you think about this fix (in Message.php line 665)? maybe this is right in other cases.
From:
($structure->ifdisposition == 1 && !isset($structure->parts) && $partNumber == null)
To:
($structure->ifdisposition == 1 && !isset($structure->parts) && $partNumber != null)
@Webklex Hello, I see that you have made the changes as suggested before, in the condition of fetchStructure, however, AFTER the last release on 2nd of July (v1.4.2) I'm having the exact same issue with email bodies being blank. Everything goes back to normal, when I change the line in Message.php. So, while it may be a fix for that specific sender, it does affect not only that sender. Could you please look into this some more?
Hi @AndriusStriupas , would you "donate" such a mail? :) I have no way to test it..
If so, please send it to imap_test[ a ]webklex.com.
Hi @AndriusStriupas , would you "donate" such a mail? :) I have no way to test it..
If so, please send it to imap_test[ a ]webklex.com.
Hello, I've sent you the email as an attachment to the provided email. Have a read at my email body, there are some explanations. Hopefully it helps you.
Hi friends, so what is the solution to this problem of bringing blank messages?
Same issue here with few examples: https://github.com/freescout-helpdesk/freescout/issues/320
Does anybody (@AndriusStriupas, @kkriszx, @kasperfd) have a recipe on how to reproduce the issue: 1) Open email client (which?) 2) Enter text (which?) 3) Send.
No need to check $structure->ifdisposition
at all, it is not reliable.
Here is the solution:
1) Change condition in https://github.com/Webklex/laravel-imap/blob/master/src/IMAP/Message.php#L662 to:
if ($structure->type == IMAP::MESSAGE_TYPE_TEXT &&
(empty($structure->disposition) || strtolower($structure->disposition) != 'attachment')
) {
2) Condition on https://github.com/Webklex/laravel-imap/blob/master/src/IMAP/Message.php#L721 can be removed:
} elseif ($structure->ifdisposition == 1 && strtolower($structure->disposition) == 'attachment') {
if ($this->getFetchAttachmentOption() === true) {
$this->fetchAttachment($structure, $partNumber);
}
}
Same issue here using Freescout @freescout-helpdesk, steps to reproduce:
Result:
This is a rather serious issue as there are millions of Apple Mail users and as a receiver you don't know what you're missing.
@imc67 issues which you are experiencing in FreeScout please post here
@freescout-helpdesk I'll do that immediately. The reason for putting it here was that you closed a similar ticket in your repository saying it was related to this ticket. Thanks for your response anyway :-)
No need to check
$structure->ifdisposition
at all, it is not reliable.Here is the solution:
- Change condition in https://github.com/Webklex/laravel-imap/blob/master/src/IMAP/Message.php#L662 to:
if ($structure->type == IMAP::MESSAGE_TYPE_TEXT && (empty($structure->disposition) || strtolower($structure->disposition) != 'attachment') ) {
- Condition on https://github.com/Webklex/laravel-imap/blob/master/src/IMAP/Message.php#L721 can be removed:
} elseif ($structure->ifdisposition == 1 && strtolower($structure->disposition) == 'attachment') { if ($this->getFetchAttachmentOption() === true) { $this->fetchAttachment($structure, $partNumber); } }
I am currently on version 1.4.4. and this solved my issue. I had only to do step 1.
Hi,
I really enjoy this plugin and I've used it for 1½ year without problems until now - so I'm thinking there must be a rare bug because it has been working for so long in version 1.2 and now 1.4.
The problem short: Many (50+) people are writing emails to us everyday without problems but for a specific person then we only get the subject + attachments fetched and both the text & html content is blank / empty.
So I hope you have some ideas of why this is happening - please tell thanks :)
Laravel: 5.4 Laravel Imap: 1.4 (latest) - the problem were also in 1.2 because I tried that version too without luck
Reproducing the problem: I tried but I cannot - so my conclusion is that the problem must exist in the email headers. Because when forwarding the e-mail to myself and back again to the IMAP inbox then the body could be fetched correctly.... I'm so lost here :)
imap config:
Email headers where the body is blank / empty and only the subject + attachments is fetched successfully. Can you spot any wierd header causing something going wrong ? I can log in to the mailbox on office 365 and see the email (I renamed recipient and sender email):