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

Error when empty headers field "from" #280

Closed
StApostol opened this issue Mar 11, 2019 · 2 comments
Closed

Error when empty headers field "from" #280

StApostol opened this issue Mar 11, 2019 · 2 comments
Assignees
Labels
enhancement This will enhance this library. need help Your support is required to solve this issue.

Comments

@StApostol
Copy link

Some time ago, spam messages with the following headings began to pour into the mail. And the parser can not parse them correctly

ErrorException: Undefined property: stdClass::$from in /vendor/php-imap/php-imap/src/PhpImap/Mailbox.php:415

Mail headers

Return-Path: <some@test.com>
Delivered-To: history@test.com
Received: from mail-it1-f200.google.com (mail-it1-f200.google.com [209.85.166.200])
	by test.com (Postfix) with ESMTPS id 8CDFF2FA08B8
	for <history@test.com>; Fri,  1 Mar 2019 11:38:11 +0100 (CET)
Received: by mail-it1-f200.google.com with SMTP id q141so11136037itc.2
        for <history@test.com>; Fri, 01 Mar 2019 02:37:19 -0800 (PST)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:dkim-signature:sender:message-id:date:subject
         :from:to:mime-version;
        bh=S5nP2Y1vTxV21X3OA6yWOBmKCvbXYypQJwDq9RJQTFU=;
        b=iVqgFjDg9mw0igsb05VVTTmDvaA465aM+cf4OS2gAvRz9aVomRvnHU5+jQRISWBKRB
         UUqIzHKCKpb40KhFWIs09qLlwg8fokSw2jMqQwwWy4B1Y5b0YzyNDI7kGnoea0fvcsGn
         xa2yY7egAcn5kpir0J7sliHkQ9bVpz8kYNIOlPYRdmY0pDSaJy8Q5SSuHN5jpjljdcMB
         VffJnMXAoO46FicZpn6KgAiHqyCxcshuBVTUhajdgNn15SMviMcKgRhPowOvSweg/MQn
         qLjMF2tJAmz32tDh0T5tbGhem3JCO8tTvP25WS6nxrbLTa/M1r7xUddPIr/hp4oVUr+B
         Ur9w==
X-Gm-Message-State: APjAAAUB96G9ctG8u/SMZyhh5Ax3AI6c/Mk/mQSDNwhMf78+pmTPZ9st
	GIYknotbjSxAw9yxE3mKdYuQ1YjY/VKemJhtrmgo2Q4yfBP0zDexWs+rsMMXIbcLaBVoPdSCObJ
	K27pkAGU7nH5icZBFbauP1yUG+wnot3NLFtUEmq/H0rz2E7gcsCsr+aGW0Lh0M1Pvjs4=
X-Received: by 2002:a24:242:: with SMTP id 63mr2712677itu.39.1551436638859;
        Fri, 01 Mar 2019 02:37:18 -0800 (PST)
X-Google-Smtp-Source: APXvYqz4cXGdg71xZ9AwQCKnv52uHyMdHeXQZCQrvpTusiA2TEvhSjXVL+j3j/gydJfl7E8gBcPJl/ZfN2U=
X-Received: by 2002:a24:242:: with SMTP id 63mr2712647itu.39.1551436637839;
        Fri, 01 Mar 2019 02:37:17 -0800 (PST)
Authentication-Results: mx.google.com;
       spf=pass (google.com: domain of bounces+6406848-614e-some=test.com@em.euvinopro.eu designates 167.89.78.28 as permitted sender) smtp.mailfrom="bounces+6406848-614e-some=test.com@em.euvinopro.eu";
       dkim=pass header.i=@euvinopro.eu header.s=s1 header.b=ENxhpXCf
Received-SPF: pass (google.com: domain of bounces+6406848-614e-some=test.com@em.euvinopro.eu designates 167.89.78.28 as permitted sender) client-ip=167.89.78.28;
Received: by 2002:a24:b303:: with POP3 id e3mf11611227itf.2;
        Fri, 01 Mar 2019 02:37:17 -0800 (PST)
X-Gmail-Fetch-Info: some@test.com 1 pop3.strato.de 995 some@test.com
X-Envelope-From: <bounces+6406848-614e-some=test.com@em.euvinopro.eu>
X-Envelope-To: <some@test.com>
X-Delivery-Time: 1551434632
X-UID: 2099
Authentication-Results: strato.com; arc=none
Authentication-Results: strato.com; dkim=pass header.d=euvinopro.eu
Authentication-Results: strato.com; spf=pass smtp.mailfrom="bounces+6406848-614e-some=test.com@em.euvinopro.eu"
X-RZG-Expurgate: clean/normal
X-RZG-Expurgate-ID: 149500::1551434632-0000071E-4FA8D969/0/0
X-Strato-MessageType: email
X-RZG-CLASS-ID: mi00
Received-SPF: pass
	(strato.com: domain em.euvinopro.eu designates 167.89.78.28 as permitted sender)
	mechanism=ip4;
	client-ip=167.89.78.28;
	helo="o1.transact.euvinopro.eu";
	envelope-from="bounces+6406848-614e-some=test.com@em.euvinopro.eu";
	receiver=smtpin.rzone.de;
	identity=mailfrom;
Received: from o1.transact.euvinopro.eu ([167.89.78.28])
	by smtpin.rzone.de (RZmta 44.13 OK)
	with ESMTPS id R04525v21A3pblA
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (curve secp521r1 with 521 ECDH bits, eq. 15360 bits RSA))
	(Client did not present a certificate)
	for <some@test.com>;
	Fri, 1 Mar 2019 11:03:51 +0100 (CET)
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=euvinopro.eu;
	h=sender:subject:from:to:mime-version:content-type; s=s1;
	bh=P5O78akNPaR42gMapI835dPUVA0=; b=ENxhpXCf4fuwXs/PnTF6v6o5yx9Ah
	VPyLkd+IJfPcRuOnoah9yn+0J7guyDCJDV3vVobbiSXzadVqVoRsgj4uTFhIg8of
	njRs1PTXoggCyz8BY6jNEDEhe7WVXPwUFV2wVA9GOvecaIkzlUkKpj+5ncPK2Y0W
	KqboGEoF8clfWk=
Received: by filter0175p3mdw1.sendgrid.net with SMTP id filter0175p3mdw1-26336-5C79037D-48
        2019-03-01 10:03:42.163559857 +0000 UTC m=+38759.148395480
Received: from localhost (bomone.euvino.eu [195.201.12.151])
	by ismtpd0002p1lon1.sendgrid.net (SG) with ESMTP id w8UFWVqgT-KY1MOqzRAFVw
	for <some@test.com>; Fri, 01 Mar 2019 10:03:41.748 +0000 (UTC)
Sender: info@euvinopro.eu
Message-ID: <8dd653721f6b64e11f5c193c467b0f2a@swift.generated>
Date: Fri, 01 Mar 2019 10:03:42 +0000 (UTC)
Subject: Katalogexport Weintour =?utf-8?Q?M=C3=BCnchen?=
From:
To: some@test.com
MIME-Version: 1.0
Content-type: multipart/alternative; boundary="----------=_1551434622-29789-1562"
X-SG-EID: n9ygyaO/DsVKb4nZ1BcUHHjLPUc9c/1oNVdV9Xekgwcjrb+HyUslv8zgOiZHdaKzdsr/svh3dqqS52
 yKm65bYJ9obzgdBjaxCSTeT6F61HStHWS5JYMYpQOzvVQmLCAvfF8jvfUZIOoGKjVz3lNvGICYdjms
 qxoGiiakAzh2Vj4uUMP0IY8Hl13lOx1CA9Eh

@Sebbo94BY
Copy link
Collaborator

Based on the RFC 822, the From: header field is required and can't be empty. See COMPLETE HEADERS, section "A.3.1. Minimum required".

RFC 822 Section 4.4.1 says this:

 4.4.1.  FROM / RESENT-FROM
 
    This field contains the identity of the person(s)  who  wished
    this  message to be sent.  The message-creation process should
    default this field  to  be  a  single,  authenticated  machine
    address,  indicating  the  AGENT  (person,  system or process)
    entering the message.  If this is not done, the "Sender" field
    MUST  be  present.  If the "From" field IS defaulted this way,
    the "Sender" field is  optional  and  is  redundant  with  the
    "From"  field.   In  all  cases, addresses in the "From" field
    must be machine-usable (addr-specs) and may not contain  named
    lists (groups).

I've updated the library to avoid throwing this error again. I've also added the Sender: header field to the headers. See commit 85d9dcb.

@StApostol are you able to test it again in order to verify the fix?

Note: This change is currently only available in the develop branch. You can simply download it as ZIP file or using composer require php-imap/php-imap:dev-develop.

@Sebbo94BY Sebbo94BY self-assigned this Apr 30, 2019
@Sebbo94BY Sebbo94BY added enhancement This will enhance this library. need help Your support is required to solve this issue. labels Apr 30, 2019
@Sebbo94BY
Copy link
Collaborator

The next release will also check, if the From: field is empty or not: lines 692-704

This solves the issue, that it throws your mentioned exception.

If it's empty, it will not even try to get any value. So you only need to check in your applications code, that fromName and fromAddress are set and not empty before using them.

Sebbo94BY added a commit that referenced this issue May 5, 2019
- Updated README
- Move phpunit to require-dev
- Add note about installing dev dependencies in README
- Replaced spaces with tabs
- Added PHPUnit tests for MIME decoding
- Updated formatting of PHPUnit function testParsedDateTimeWithEmptyHeaderDate()
- Issue #209: Function to parse datetime correctly RFC2822
- Issue #280: Added 'Sender' to headers and added additional if-conditions 
- Issue #115: getMail() method returns an object even for nonexistent mail ID
- Issue #273: Added connection check to example
- Issue #227: Added Failed-Recipients to IncomingMailHeader
- Issue #140, #246: Improved exception handling and added PHPUnit test
- Issue #140: Added PHPUnit test for testing ConnectionException
- Issue #140: Improved exception / error handling and improved / added PHPUnit tests
- Issue #154: Added ability to change the imap_search option from SE_UID to SE_FREE and added PHPUnit tests
- Issue #306: Added support for US-ASCII and added ability to disable serverEncoding for searchMailbox()
- Imported missing namespaces to avoid 'unknown class' error messages
- Issue #86: Simplified and improved one replace regex for attachment file names
- Issue #247: Improved grabbing of fromName, fromHost, senderName and senderHost
- Issue #39, #71, #229: Fixed body content gets incorrectly processed as attachments
- Issue #122, #150, #167: Added ability to skip processing of attachments to increase performance, when attachments are not required
- PR #284: Added missing PHPUnit tests
- Issue #122, #150, #167: Lazy load message text and attachments data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement This will enhance this library. need help Your support is required to solve this issue.
Projects
None yet
Development

No branches or pull requests

2 participants